Documentation ¶
Index ¶
- func Handler(verificationKey string) routing.Handler
- func MockAuthHandler(c *routing.Context) error
- func MockAuthHeader() http.Header
- func RegisterHandlers(rg *routing.RouteGroup, service Service, logger log.Logger)
- func WithUser(ctx context.Context, id, name string) context.Context
- type Identity
- type Service
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MockAuthHandler ¶
MockAuthHandler creates a mock authentication middleware for testing purpose. If the request contains an Authorization header whose value is "TEST", then it considers the user is authenticated as "Tester" whose ID is "100". It fails the authentication otherwise.
func MockAuthHeader ¶
MockAuthHeader returns an HTTP header that can pass the authentication check by MockAuthHandler.
func RegisterHandlers ¶
func RegisterHandlers(rg *routing.RouteGroup, service Service, logger log.Logger)
RegisterHandlers registers handlers for different HTTP requests.
Types ¶
type Identity ¶
type Identity interface { // GetID returns the user ID. GetID() string // GetName returns the user name. GetName() string }
Identity represents an authenticated user identity.
func CurrentUser ¶
CurrentUser returns the user identity from the given context. Nil is returned if no user identity is found in the context.
type Service ¶
type Service interface { // authenticate authenticates a user using username and password. // It returns a JWT token if authentication succeeds. Otherwise, an error is returned. Login(ctx context.Context, username, password string) (string, error) }
Service encapsulates the authentication logic.
Click to show internal directories.
Click to hide internal directories.