Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Group ¶
func Group( logger *zap.SugaredLogger, cache cache.Cache, db database.Database, email email.ConfigOptions, secrets ConfigOptions, r *mux.Router, )
Group groups all authentication routers.
Types ¶
type AuthenticationMiddleware ¶
type AuthenticationMiddleware struct { AccessUUID string ForgeedUserID uint64 // ForgeedUserID is a forged id responding to frontend UserID uint64 // contains filtered or unexported fields }
AuthenticationMiddleware is a general JWT token validation, it also checks users in cache system.
func New ¶
func New(logger *zap.SugaredLogger, cache cache.Cache, secrets ConfigOptions) *AuthenticationMiddleware
New returns a new AuthenticationMiddleware
func (*AuthenticationMiddleware) GetUserID ¶
func (amw *AuthenticationMiddleware) GetUserID() uint64
GetUserID returns a parsed and existing user's real id in databae.
func (*AuthenticationMiddleware) MiddlewareMustAuthenticate ¶
func (amw *AuthenticationMiddleware) MiddlewareMustAuthenticate(next http.Handler) http.Handler
MiddlewareMustAuthenticate Implements mux.MiddlewareMustAuthenticate, which will be called for each request that needs authentication.
func (*AuthenticationMiddleware) MiddlewareOptionallyAuthenticate ¶
func (amw *AuthenticationMiddleware) MiddlewareOptionallyAuthenticate(next http.Handler) http.Handler
MiddlewareOptionallyAuthenticate can be used in route which optionally needs authentication. If a user is authenticated, this middleware parses the request token and extract user metedata. You can use either this middleware or MiddlewareMustAuthenticate but not both.
type ConfigOptions ¶
type ConfigOptions struct {
AccessSecret, RefreshSecret string
}
ConfigOptions provides all config options auth needs.