auth

package
v0.4.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 24, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package auth implements functionality to verify tokens from Firebase Authentication.

Index

Constants

View Source
const ErrEmailNotVerified = 3
View Source
const ErrInvalidCustomClaims = 4
View Source
const ErrTokenExpired = 1
View Source
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

type AuthChecker interface {
	IsAuthenticated(ctx context.Context, token string) (User, error)
}

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.

type ClaimsFunc

type ClaimsFunc func(map[string]interface{}) (interface{}, error)

type ContextBuilderFunc

type ContextBuilderFunc func(context.Context, User) context.Context

type User

type User struct {
	Uid          string
	CustomClaims interface{}
}

User built from the data in a JWT token.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL