Documentation ¶
Overview ¶
Package auth implements functionality to verify tokens from Firebase Authentication.
Index ¶
Constants ¶
const ErrEmailNotVerified = 3
const ErrInvalidCustomClaims = 4
const ErrTokenExpired = 1
const ErrTokenInvalid = 2
Variables ¶
This section is empty.
Functions ¶
func NewAuthEndpointMiddleware ¶
func NewAuthEndpointMiddleware(ac AuthChecker, ctxBuilder ContextBuilderFunc) endpoint.Middleware
Go kit endpoint middleware that uses an instance of AuthChecker to check if the request is authenticated, i.e. AuthChecker accepts the token obtained from the context. The token should be stored in the context using the JWTContextKey from package "github.com/go-kit/kit/auth/jwt".
If the token is valid the User value returned by the IsAuthenticated method of AuthChecker is passed into "ctxBuilder", which can return a new context that e.g. has the user stored as a value.
If the request is not authenticated, the middleware will return an error immediately and not call the next endpoint handler.
Types ¶
type AuthChecker ¶
AuthChecker checks if a given JWT token is a valid Firebase Authentication token. If the token is valid, a User that contains the user id and custom claims is returned.
func NewAuthChecker ¶
func NewAuthChecker(authClient *auth.Client, requireVerifiedEmail bool, validateClaims ClaimsFunc) AuthChecker
Returns a new instance of AuthChecker. If "requireVerifiedEmail" is true, the email of a user must be verified for a token to be considered valid. Furthermore a function to validate and extract custom claims of a user can be provided. A token will only be considered valid if this function returns a nil error. The first return value of the function is used to set the "CustomClaims" field of the User value returned.