authenticate

package
v0.0.0-...-0985497 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2024 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HasHeaderToken

func HasHeaderToken(r *http.Request) bool

HasHeaderToken tests if the request header has a token without verifying the correctness.

func HasSessionToken

func HasSessionToken(manager *scs.Manager, r *http.Request) bool

HasSessionToken tests if the request header has the http-only cookies containing session informations.

func NewSessionAuth

func NewSessionAuth(config *configuration.AuthenticationConfiguration) *scs.Manager

createSessionManager starts a web session and stores the information into a http-only cookie. This is the preferred way when using a SPA.

func RateLimitMiddleware

func RateLimitMiddleware(ll *LoginLimiter) func(h http.Handler) http.Handler

func RateLimitMiddleware(prefix string, limit string, redisURL string) func(h http.Handler) http.Handler {

func RequiredValidAccessClaims

func RequiredValidAccessClaims(manager *scs.Manager, config *configuration.ServerConfigurationSchema) func(http.Handler) http.Handler

RequiredValidAccessClaimsMiddleware tries to get information about the identity which issues a request by looking into the authorization header and then into the cookie.

Types

type AccessClaims

type AccessClaims struct {
	jwt.StandardClaims
	AccessNotRefresh bool  `json:"anr"`      // to distinguish between access and refresh code
	LoginID          int64 `json:"login_id"` // the id to get user information
	Root             bool  `json:"root"`     // a global flag to bypass all permission checks
}

AccessClaims represent the claims parsed from JWT access token.

func NewAccessClaims

func NewAccessClaims(loginId int64, root bool) AccessClaims

func (*AccessClaims) DestroyInSession

func (ret *AccessClaims) DestroyInSession(manager *scs.Manager, w http.ResponseWriter, r *http.Request) error

func (*AccessClaims) ParseAccessClaimsFromToken

func (ret *AccessClaims) ParseAccessClaimsFromToken(secret string, tokenStr string) error

Parse access claims from a JWT token string

func (*AccessClaims) ParseRefreshClaimsFromSession

func (ret *AccessClaims) ParseRefreshClaimsFromSession(manager *scs.Manager, r *http.Request) error

Parse access claims from a cookie

func (*AccessClaims) ToMap

func (a *AccessClaims) ToMap() map[string]interface{}

func (*AccessClaims) UpdateSession

func (ret *AccessClaims) UpdateSession(manager *scs.Manager, w http.ResponseWriter, r *http.Request) http.ResponseWriter

func (*AccessClaims) WriteToSession

func (ret *AccessClaims) WriteToSession(manager *scs.Manager, w http.ResponseWriter, r *http.Request) http.ResponseWriter

type LoginLimiter

type LoginLimiter struct {
	Store  *limiter.Store
	Rate   *limiter.Rate
	Prefix string
	Redis  *libredis.Client
}

func NewLoginLimiter

func NewLoginLimiter(prefix string, limit string, redisURL string) (*LoginLimiter, error)

func (*LoginLimiter) Get

func (ll *LoginLimiter) Get(r *http.Request, KeyFunc LoginLimiterKey) (limiter.Context, error)

func (*LoginLimiter) WriteHeaders

func (ll *LoginLimiter) WriteHeaders(w http.ResponseWriter, context limiter.Context)

type LoginLimiterKey

type LoginLimiterKey interface {
	Key() string
}

type LoginLimiterKeyFromIP

type LoginLimiterKeyFromIP struct {
	R *http.Request
}

func NewLoginLimiterKeyFromIP

func NewLoginLimiterKeyFromIP(r *http.Request) *LoginLimiterKeyFromIP

func (*LoginLimiterKeyFromIP) Key

func (obj *LoginLimiterKeyFromIP) Key() string

type RefreshClaims

type RefreshClaims struct {
	jwt.StandardClaims
	AccessNotRefresh bool  `json:"anr"`
	LoginID          int64 `json:"login_id"`
}

RefreshClaims represent the claims parsed from JWT refresh token.

func NewRefreshClaims

func NewRefreshClaims(loginId int64) RefreshClaims

func (*RefreshClaims) ParseRefreshClaimsFromToken

func (ret *RefreshClaims) ParseRefreshClaimsFromToken(secret string, tokenStr string) error

Parse refresh claims from a token string

func (*RefreshClaims) ToMap

func (a *RefreshClaims) ToMap() map[string]interface{}

type TokenAuth

type TokenAuth struct {
	JwtAuth          *jwtauth.JWTAuth
	JwtAccessExpiry  time.Duration
	JwtRefreshExpiry time.Duration
}

TokenAuth implements JWT authentication flow.

func NewTokenAuth

NewTokenAuth configures and returns a JWT authentication instance.

func (*TokenAuth) CreateAccessJWT

func (a *TokenAuth) CreateAccessJWT(claims AccessClaims) (string, error)

CreateAccessJWT returns an access token for provided account claims.

func (*TokenAuth) CreateRefreshJWT

func (a *TokenAuth) CreateRefreshJWT(claims RefreshClaims) (string, error)

CreateRefreshJWT returns a refresh token for provided token Claims.

func (*TokenAuth) Verifier

func (a *TokenAuth) Verifier() func(http.Handler) http.Handler

Verifier http middleware will verify a jwt string from a http request.

Jump to

Keyboard shortcuts

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