auth

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: May 26, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Middleware

type Middleware interface {
	AllOfRoles(requiredRoles ...string) gin.HandlerFunc
	AnyOfRoles(allowedRoles ...string) gin.HandlerFunc
	AnyAuthenticated() gin.HandlerFunc
}

func NewAuthMiddleware

func NewAuthMiddleware(verifier TokenVerifier) Middleware

func NewMockedAuthMiddleware

func NewMockedAuthMiddleware(mockedToken *TokenContext) Middleware

type TokenContext

type TokenContext struct {
	ID        string    `json:"id,omitempty"        bson:"_id,omitempty"`
	IssuedAt  time.Time `json:"issuedAt"            bson:"issuedAt"`
	ExpiresAt time.Time `json:"expiresAt,omitempty" bson:"expiresAt,omitempty"`
	Issuer    string    `json:"issuer,omitempty"    bson:"issuer,omitempty"`
	Subject   string    `json:"subject,omitempty"   bson:"subject,omitempty"`
	IP        string    `json:"ip,omitempty"        bson:"ip,omitempty"`
	Roles     []string  `json:"roles"               bson:"roles"`
	Resources []string  `json:"resources"           bson:"resources"`
	Raw       string    `json:"raw"                 bson:"raw"`
}

func GetTokenContext

func GetTokenContext(c *gin.Context) *TokenContext

type TokenGenerator

type TokenGenerator interface {
	Generate(...TokenOpt) (string, error)
}

type TokenManager

type TokenManager interface {
	TokenVerifier
	TokenGenerator
	TokenRevoker
}

type TokenOpt

type TokenOpt = func(*TokenOptions)

func Duration

func Duration(duration time.Duration) TokenOpt

func IP

func IP(ip string) TokenOpt

func Issuer

func Issuer(issuer string) TokenOpt

func Resources

func Resources(resources ...string) TokenOpt

func Roles

func Roles(roles ...string) TokenOpt

func Subject

func Subject(subject string) TokenOpt

type TokenOptions

type TokenOptions struct {
	Issuer    string
	Subject   string
	IP        string
	Duration  time.Duration
	Roles     []string
	Resources []string
}

type TokenRevoker

type TokenRevoker interface {
	Revoke(*TokenContext) error
}

type TokenVerifier

type TokenVerifier interface {
	Verify(tokenString string) (*TokenContext, error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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