auth

package
v0.0.0-...-fa6ae4b Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2021 License: GPL-3.0 Imports: 26 Imported by: 0

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.

type CredsPairInfo

type CredsPairInfo struct {
	AccessToken     string
	RefreshToken    string
	AccessUUID      string
	RefreshUUID     string
	AccessExpireAt  int64
	RefreshExpireAt int64
}

CredsPairInfo is an authenticated user credentials collection.

type IDs

type IDs struct {
	UUID   string
	UserID uint64
}

IDs is either access ids or refresh ids.

Jump to

Keyboard shortcuts

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