bearer

package
v0.0.0-...-7578c0e Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultMaxTokenLifetime = 90 * 24 * time.Hour
	DefaultTokenLifetime    = 10 * time.Minute
)

Variables

View Source
var Scopes2FaCheckOnly = []Scope{
	{
		URI:    routes.AllRoutesPrefix + routes.Verify2FaRoute,
		Method: http.MethodPost,
	},
}
View Source
var ScopesAllExcluding2FaCheck = []Scope{
	{
		URI:    "*",
		Method: "*",
	},
	{
		URI:     routes.AllRoutesPrefix + routes.Verify2FaRoute,
		Method:  "*",
		Exclude: true,
	},
}
View Source
var ScopesTotPCreateOnly = []Scope{
	{
		URI:    routes.AllRoutesPrefix + routes.TotPRoutes,
		Method: http.MethodPost,
	},
}

Functions

func CreateAuthToken

func CreateAuthToken(
	ctx context.Context,
	sessionUpdater APISessionUpdater,
	JWTSecret string,
	lifetime time.Duration,
	username string,
	scopes []Scope,
	userAgent string,
	remoteAddress string,
) (string, error)

func GetBearerToken

func GetBearerToken(req *http.Request) (string, bool)

func IncreaseSessionLifetime

func IncreaseSessionLifetime(
	ctx context.Context,
	sessionUpdater APISessionUpdater,
	s session.APISession) error

func ValidateBearerToken

func ValidateBearerToken(
	ctx context.Context,
	tokCtx *TokenContext,
	uri, method string,
	apiSessionGetter APISessionGetter,
	l *logger.Logger) (valid bool, sessionInfo session.APISession, err error)

Types

type APISessionGetter

type APISessionGetter interface {
	Get(ctx context.Context, sessionID int64) (found bool, sessionInfo session.APISession, err error)
}

type APISessionUpdater

type APISessionUpdater interface {
	Save(ctx context.Context, session session.APISession) (sessionID int64, err error)
}

type AppTokenClaims

type AppTokenClaims struct {
	Username  string  `json:"username,omitempty"`
	SessionID int64   `json:"sessionID,omitempty"`
	Scopes    []Scope `json:"scopes,omitempty"`
	jwt.StandardClaims
}

type Scope

type Scope struct {
	URI     string `json:"uri,omitempty"`
	Method  string `json:"method,omitempty"`
	Exclude bool   `json:"exclude,omitempty"`
}

type TokenContext

type TokenContext struct {
	AppClaims *AppTokenClaims
	RawToken  string
	JwtToken  *jwt.Token
}

func ParseToken

func ParseToken(tokenStr string, JWTSecret string) (tokCtx *TokenContext, err error)

Jump to

Keyboard shortcuts

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