2021-07-21 23:04:00 +00:00
|
|
|
package auth
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2022-03-13 10:58:34 +00:00
|
|
|
"source.toby3d.me/toby3d/auth/internal/domain"
|
2021-07-21 23:04:00 +00:00
|
|
|
)
|
|
|
|
|
2022-01-13 20:49:08 +00:00
|
|
|
type (
|
|
|
|
GenerateOptions struct {
|
|
|
|
ClientID *domain.ClientID
|
2022-01-29 19:31:52 +00:00
|
|
|
Me *domain.Me
|
2022-01-13 20:49:08 +00:00
|
|
|
RedirectURI *domain.URL
|
|
|
|
CodeChallengeMethod domain.CodeChallengeMethod
|
|
|
|
Scope domain.Scopes
|
2022-01-29 19:31:52 +00:00
|
|
|
CodeChallenge string
|
2022-01-13 20:49:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ExchangeOptions struct {
|
|
|
|
ClientID *domain.ClientID
|
|
|
|
RedirectURI *domain.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",
|
|
|
|
)
|
|
|
|
)
|