auth

package
v0.0.0-...-3266887 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2022 License: Apache-2.0, BSD-2-Clause, BSD-3-Clause, + 2 more Imports: 11 Imported by: 0

Documentation

Overview

Package auth defines authentication strategy like Basic, Bearer.

Index

Constants

View Source
const AuthzAudience = "iam.authz.marmotedu.com"

AuthzAudience defines the value of jwt audience field.

Variables

View Source
var (
	ErrMissingKID    = errors.New("Invalid token format: missing kid field in claims")
	ErrMissingSecret = errors.New("Can not obtain secret information from cache")
)

Defined errors.

Functions

func KeyExpired

func KeyExpired(expires int64) bool

KeyExpired checks if a key has expired, if the value of user.SessionState.Expires is 0, it will be ignored.

Types

type AutoStrategy

type AutoStrategy struct {
	// contains filtered or unexported fields
}

AutoStrategy defines authentication strategy which can automatically choose between Basic and Bearer according `Authorization` header.

func NewAutoStrategy

func NewAutoStrategy(basic, jwt middleware.AuthStrategy) AutoStrategy

NewAutoStrategy create auto strategy with basic strategy and jwt strategy.

func (AutoStrategy) AuthFunc

func (a AutoStrategy) AuthFunc() gin.HandlerFunc

AuthFunc defines auto strategy as the gin authentication middleware.

type BasicStrategy

type BasicStrategy struct {
	// contains filtered or unexported fields
}

BasicStrategy defines Basic authentication strategy.

func NewBasicStrategy

func NewBasicStrategy(compare func(username string, password string) bool) BasicStrategy

NewBasicStrategy create basic strategy with compare function.

func (BasicStrategy) AuthFunc

func (b BasicStrategy) AuthFunc() gin.HandlerFunc

AuthFunc defines basic strategy as the gin authentication middleware.

type CacheStrategy

type CacheStrategy struct {
	// contains filtered or unexported fields
}

CacheStrategy defines jwt bearer authentication strategy which called `cache strategy`. Secrets are obtained through grpc api interface and cached in memory.

func NewCacheStrategy

func NewCacheStrategy(get func(kid string) (Secret, error)) CacheStrategy

NewCacheStrategy create cache strategy with function which can list and cache secrets.

func (CacheStrategy) AuthFunc

func (cache CacheStrategy) AuthFunc() gin.HandlerFunc

AuthFunc defines cache strategy as the gin authentication middleware.

type JWTStrategy

type JWTStrategy struct {
	ginjwt.GinJWTMiddleware
}

JWTStrategy defines jwt bearer authentication strategy.

func NewJWTStrategy

func NewJWTStrategy(gjwt ginjwt.GinJWTMiddleware) JWTStrategy

NewJWTStrategy create jwt bearer strategy with GinJWTMiddleware.

func (JWTStrategy) AuthFunc

func (j JWTStrategy) AuthFunc() gin.HandlerFunc

AuthFunc defines jwt bearer strategy as the gin authentication middleware.

type Secret

type Secret struct {
	Username string
	ID       string
	Key      string
	Expires  int64
}

Secret contains the basic information of the secret key.

Jump to

Keyboard shortcuts

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