Documentation
¶
Index ¶
- Variables
- func GetSessionUser(ctx context.Context) (*model.User, bool)
- func NewMiddleware(opts ...MiddlewareOption) func(http.Handler) http.Handler
- func NewModule() *service.UserModule
- func SetSessionUser(ctx context.Context, u *model.User) context.Context
- func SigningKey() string
- type Middleware
- type MiddlewareOption
Constants ¶
This section is empty.
Variables ¶
var ErrLoginRequired = errors.New("login required")
ErrLoginRequired is returned with RequireLoginError middleware.
Functions ¶
func GetSessionUser ¶
GetSessionUser will return the user bound to the session. If there's no active user bound, the return is nil, false.
func NewMiddleware ¶
func NewMiddleware(opts ...MiddlewareOption) func(http.Handler) http.Handler
NewMiddleware will populate context for IsLoggedIn, GetSessionUser.
func SetSessionUser ¶
SetSessionUser is here to aid testing, for internal use.
func SigningKey ¶
func SigningKey() string
Types ¶
type Middleware ¶
type Middleware struct {
// contains filtered or unexported fields
}
Middleware requires a user login for the registered route. If an Authorize header is provided, it will decode the JWT and use the user_id claim to authenticate API requests.
How do you generate the JWT you ask? Good question. TBD.
func (*Middleware) ServeHTTP ¶
func (m *Middleware) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP authenticates the request and passes it to the next handler.
type MiddlewareOption ¶
type MiddlewareOption func(*Middleware)
MiddlewareOption configures the user authentication middleware.
func AuthCookie ¶
func AuthCookie() MiddlewareOption
AuthCookie enables session-based authentication via a cookie.
func AuthHeader ¶
func AuthHeader() MiddlewareOption
AuthHeader enables JWT-based authentication via the Authorization header.
func AuthQuery ¶
func AuthQuery(paramName string) MiddlewareOption
AuthQuery enables JWT-based authentication via URL query parameter. Useful for headless browsers that can't set Authorization headers.