Documentation
¶
Index ¶
- Constants
- Variables
- func Authenticate(v JWSVerifier, ctx context.Context, input *openapi3filter.AuthenticationInput) error
- func GetAuthMiddleware(swagger *openapi3.T, v JWSVerifier) func(next http.Handler) http.Handler
- func GetUserIDFromContext(ctx context.Context) (uuid.UUID, error)
- func GetUserIDFromToken(t jwt.Token) (uuid.UUID, error)
- func NewAuthenticator(v JWSVerifier) openapi3filter.AuthenticationFunc
- type JWSSigner
- type JWSVerifier
- type LocalJWSSigner
- func (s *LocalJWSSigner) CreateAccessToken(userID uuid.UUID, claims []string) (string, time.Duration, error)
- func (s *LocalJWSSigner) CreatePasswordResetToken(userID uuid.UUID) (string, time.Duration, error)
- func (s *LocalJWSSigner) CreateRefreshToken(userID uuid.UUID) (string, time.Duration, error)
- func (s *LocalJWSSigner) CreateVerifyAccountToken(userID uuid.UUID) (string, time.Duration, error)
- type LocalJWSVerifier
Constants ¶
const PermissionsClaim = "permissions"
const TypeClaim = "type"
const TypePasswordReset = "password_reset"
const TypeVerifyAccount = "verify_account"
const UserIDContextKey = "userID"
Variables ¶
Functions ¶
func Authenticate ¶
func Authenticate(v JWSVerifier, ctx context.Context, input *openapi3filter.AuthenticationInput) error
Authenticate uses the specified validator to ensure a JWT is valid, then makes sure that the claims provided by the JWT match the scopes as required in the API.
func GetAuthMiddleware ¶
GetAuthMiddleware returns a middleware for validating requests against the OpenAPI spec.
func GetUserIDFromContext ¶
GetUserIDFromContext retrieves the user ID from the context.
func GetUserIDFromToken ¶
Get userID from token
func NewAuthenticator ¶
func NewAuthenticator(v JWSVerifier) openapi3filter.AuthenticationFunc
Types ¶
type JWSSigner ¶
type JWSSigner interface {
CreateAccessToken(userID uuid.UUID, claims []string) (string, time.Duration, error)
CreateRefreshToken(userID uuid.UUID) (string, time.Duration, error)
CreatePasswordResetToken(userID uuid.UUID) (string, time.Duration, error)
CreateVerifyAccountToken(userID uuid.UUID) (string, time.Duration, error)
}
type JWSVerifier ¶
type LocalJWSSigner ¶
type LocalJWSSigner struct {
// contains filtered or unexported fields
}
func NewLocalJWSSigner ¶
func NewLocalJWSSigner( privateKeySource source.SourceProvider, issuer, audience string, accessTokenExpiresIn time.Duration, refreshTokenExpiresIn time.Duration, ) (*LocalJWSSigner, error)
func (*LocalJWSSigner) CreateAccessToken ¶
func (s *LocalJWSSigner) CreateAccessToken(userID uuid.UUID, claims []string) (string, time.Duration, error)
CreateAccessToken creates a JWS with the given user ID and claims. The claims are added to the "permissions" claim in the JWS.
func (*LocalJWSSigner) CreatePasswordResetToken ¶
CreatePasswordResetToken creates a refresh JWS
func (*LocalJWSSigner) CreateRefreshToken ¶
CreateRefreshToken creates a refresh JWS
func (*LocalJWSSigner) CreateVerifyAccountToken ¶
CreateVerifyAccountToken creates a refresh JWS
type LocalJWSVerifier ¶
type LocalJWSVerifier struct {
// contains filtered or unexported fields
}
func NewLocalJWSVerifier ¶
func NewLocalJWSVerifier(publicKeySource source.SourceProvider, issuer, audience string) (*LocalJWSVerifier, error)
func (*LocalJWSVerifier) ValidatePasswordResetToken ¶
func (v *LocalJWSVerifier) ValidatePasswordResetToken(jwsString string) (jwt.Token, error)
ValidatePasswordToken ensures that the critical JWT claims needed to ensure that we trust the JWT are present and with the correct values.
func (*LocalJWSVerifier) ValidateToken ¶
func (v *LocalJWSVerifier) ValidateToken(jwsString string) (jwt.Token, error)
ValidateToken ensures that the critical JWT claims needed to ensure that we trust the JWT are present and with the correct values.