auth

package
v0.0.0-...-f450a9d Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2019 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const AuthorizationContextKey = "PLAID_UI_PUBLIC_API_AUTHORIZATION"

AuthorizationContextKey is the key used to store the Authorization in the context

Variables

This section is empty.

Functions

This section is empty.

Types

type Authorization

type Authorization struct {
	jwt.StandardClaims
	UserUUID string `json:"sub,omitempty"`
	Email    string `json:"eml,omitempty"`
	Admin    bool   `json:"login.adm,omitempty"`
	User     bool   `json:"login.user,omitempty"`
}

Authorization describes the authorities stored in a user JWT

func GetAuthorizationFromContext

func GetAuthorizationFromContext(c *gin.Context) (Authorization, bool)

GetAuthorizationFromContext is the default Getter

func (*Authorization) Valid

func (a *Authorization) Valid() error

Valid applies standard JWT validations as well as generic user authorization rules.

type AuthorizationManager

type AuthorizationManager interface {
	BackendMiddleware() gin.HandlerFunc
	FrontendMiddleware() gin.HandlerFunc
}

AuthorizationManager exposes middleware functionality for authorization

type Authorizer

type Authorizer interface {
	ParseWithClaims(tokenString string, claims jwt.Claims, keyFunc jwt.Keyfunc) (*jwt.Token, error)
}

Authorizer represents the needed interactions with jwt.Parser

type Getter

type Getter func(c *gin.Context) (Authorization, bool)

Getter is a helper for grabbing the Authorization that the middleware stores in the context.

type JWTAuthorizationManager

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

JWTAuthorizationManager provides a JWT-based implementation of AuthorizationManager

func NewAuthorizationManager

func NewAuthorizationManager(
	logger tools.Logger,
	renderer views.Renderer,
	signingSecret string,
	authorizer Authorizer,
	db db.DB,
	loginBaseURLRef *url.URL,
) JWTAuthorizationManager

NewAuthorizationManager creates a new JWTAuthorizationManager

func (JWTAuthorizationManager) BackendMiddleware

func (a JWTAuthorizationManager) BackendMiddleware() gin.HandlerFunc

BackendMiddleware checks for a JWT in a bearer token on the request and converts it into an Authorzation struct, which is stored in the context.

func (JWTAuthorizationManager) FrontendMiddleware

func (a JWTAuthorizationManager) FrontendMiddleware() gin.HandlerFunc

FrontendMiddleware checks for a JWT in a request token. If it's not there or invalid, redirect the user to the login flow, with instructions to refer the user back here afterwards.

Jump to

Keyboard shortcuts

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