2021-07-21 23:04:00 +00:00
|
|
|
package auth
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2023-01-02 01:15:11 +00:00
|
|
|
"net/url"
|
2021-07-21 23:04:00 +00:00
|
|
|
|
2022-03-13 10:58:34 +00:00
|
|
|
"source.toby3d.me/toby3d/auth/internal/domain"
|
2024-05-06 15:58:14 +00:00
|
|
|
"source.toby3d.me/toby3d/auth/internal/domain/challenge"
|
2021-07-21 23:04:00 +00:00
|
|
|
)
|
|
|
|
|
2022-01-13 20:49:08 +00:00
|
|
|
type (
|
|
|
|
GenerateOptions struct {
|
2023-01-14 21:27:37 +00:00
|
|
|
ClientID domain.ClientID
|
|
|
|
Me domain.Me
|
2023-01-02 01:15:11 +00:00
|
|
|
RedirectURI *url.URL
|
2024-05-06 15:58:14 +00:00
|
|
|
CodeChallengeMethod challenge.Method
|
2022-01-29 19:31:52 +00:00
|
|
|
CodeChallenge string
|
2023-07-06 23:11:53 +00:00
|
|
|
Scope domain.Scopes
|
2022-01-13 20:49:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ExchangeOptions struct {
|
2023-01-14 21:27:37 +00:00
|
|
|
ClientID domain.ClientID
|
2023-01-02 01:15:11 +00:00
|
|
|
RedirectURI *url.URL
|
2022-01-29 19:31:52 +00:00
|
|
|
Code string
|
2022-01-13 20:49:08 +00:00
|
|
|
CodeVerifier string
|
|
|
|
}
|
|
|
|
|
|
|
|
UseCase interface {
|
|
|
|
Generate(ctx context.Context, opts GenerateOptions) (string, error)
|
2022-02-17 16:10:52 +00:00
|
|
|
Exchange(ctx context.Context, opts ExchangeOptions) (*domain.Me, *domain.Profile, error)
|
2022-01-13 20:49:08 +00:00
|
|
|
}
|
|
|
|
)
|
2022-02-02 21:12:09 +00:00
|
|
|
|
|
|
|
var (
|
|
|
|
ErrMismatchClientID error = domain.NewError(
|
|
|
|
domain.ErrorCodeInvalidRequest,
|
|
|
|
"client's URL MUST match the client_id used in the authentication request",
|
|
|
|
"https://indieauth.net/source/#request",
|
|
|
|
)
|
|
|
|
ErrMismatchRedirectURI error = domain.NewError(
|
|
|
|
domain.ErrorCodeInvalidRequest,
|
|
|
|
"client's redirect URL MUST match the initial authentication request",
|
|
|
|
"https://indieauth.net/source/#request",
|
|
|
|
)
|
|
|
|
ErrMismatchPKCE error = domain.NewError(
|
|
|
|
domain.ErrorCodeInvalidRequest,
|
|
|
|
"code_verifier is not hashes to the same value as given in the code_challenge in the original "+
|
|
|
|
" authorization request",
|
|
|
|
"https://indieauth.net/source/#request",
|
|
|
|
)
|
|
|
|
)
|