auth

package
v0.15.2 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2024 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ByBasicAuth = "basicAuth"

	AttributeUser = "user"
)
View Source
const (
	ByApiKey     = "apiKey"
	HeaderApiKey = "X-API-KEY"

	AttributeApiKey = "apiKey"
)
View Source
const (
	ByTokenBearer = "tokenBearer"

	AttributeToken         = "token"
	AttributeTokenBearerId = "tokenBearerId"
	AttributeTokenBearer   = "tokenBearer"
)
View Source
const Anonymous = "anon"
View Source
const ByGoogle = "google"
View Source
const (
	ByJWT = "jwtAuth"
)

Variables

This section is empty.

Functions

func NewBasicAuthHandler

func NewBasicAuthHandler(config cfg.Config, logger log.Logger) (gin.HandlerFunc, error)

func NewChainHandler

func NewChainHandler(authenticators map[string]Authenticator) gin.HandlerFunc

func NewConfigGoogleHandler

func NewConfigGoogleHandler(config cfg.Config, logger log.Logger) (gin.HandlerFunc, error)

func NewConfigKeyHandler

func NewConfigKeyHandler(config cfg.Config, logger log.Logger, provider ApiKeyProvider) gin.HandlerFunc

func NewJwtAuthHandler

func NewJwtAuthHandler(config cfg.Config, name string) gin.HandlerFunc

func NewTokenBearerHandler

func NewTokenBearerHandler(config cfg.Config, logger log.Logger, provider TokenBearerProvider) gin.HandlerFunc

func NewUncheckedKeyHandler

func NewUncheckedKeyHandler(config cfg.Config, logger log.Logger, provider ApiKeyProvider) gin.HandlerFunc

func RequestWithSubject

func RequestWithSubject(ginCtx *gin.Context, subject *Subject)

Types

type ApiKeyProvider

type ApiKeyProvider func(ginCtx *gin.Context) string

func ProvideValueFromHeader

func ProvideValueFromHeader(header string) ApiKeyProvider

func ProvideValueFromQueryParam

func ProvideValueFromQueryParam(queryParam string) ApiKeyProvider

func ProvideValueFromUriPath

func ProvideValueFromUriPath(param string) ApiKeyProvider

type Authenticator

type Authenticator interface {
	IsValid(ginCtx *gin.Context) (bool, error)
}

func NewBasicAuthAuthenticator

func NewBasicAuthAuthenticator(config cfg.Config, logger log.Logger) (Authenticator, error)

func NewBasicAuthAuthenticatorWithInterfaces

func NewBasicAuthAuthenticatorWithInterfaces(logger log.Logger, users map[string]string) Authenticator

func NewConfigGoogleAuthenticator

func NewConfigGoogleAuthenticator(config cfg.Config, logger log.Logger) (Authenticator, error)

func NewConfigGoogleAuthenticatorWithInterfaces

func NewConfigGoogleAuthenticatorWithInterfaces(logger log.Logger, tokenProvider TokenInfoProvider, clientIds []string, allowedAddresses []string) Authenticator

func NewConfigKeyAuthenticator

func NewConfigKeyAuthenticator(config cfg.Config, logger log.Logger, provider ApiKeyProvider) Authenticator

func NewConfigKeyAuthenticatorWithInterfaces

func NewConfigKeyAuthenticatorWithInterfaces(logger log.Logger, keys []string, provider ApiKeyProvider) Authenticator

func NewJWTAuthAuthenticator

func NewJWTAuthAuthenticator(config cfg.Config, name string) Authenticator

func NewJWTAuthAuthenticatorWithInterfaces

func NewJWTAuthAuthenticatorWithInterfaces(jwtTokenHandler JwtTokenHandler) Authenticator

func NewTokenBearerAuthenticator

func NewTokenBearerAuthenticator(config cfg.Config, logger log.Logger, provider TokenBearerProvider) Authenticator

func NewTokenBearerAuthenticatorWithInterfaces

func NewTokenBearerAuthenticatorWithInterfaces(logger log.Logger, keyHeader string, tokenHeader string, provider TokenBearerProvider) Authenticator

func NewUncheckedKeyAuthenticator

func NewUncheckedKeyAuthenticator(_ cfg.Config, logger log.Logger, provider ApiKeyProvider) Authenticator

func NewUncheckedKeyAuthenticatorWithInterfaces

func NewUncheckedKeyAuthenticatorWithInterfaces(logger log.Logger, provider ApiKeyProvider) Authenticator

type Getter

type Getter func(ctx context.Context, key string, value TokenBearer) (bool, error)

A Getter retrieves a value from the store by the given key. If the value does not exist, false is returned and value is not modified. value should be a pointer to the model you want to retrieve.

type GoogleTokenProvider

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

func (*GoogleTokenProvider) GetTokenInfo

func (p *GoogleTokenProvider) GetTokenInfo(idToken string) (*oauth2.Tokeninfo, error)

type InvalidBearerErr

type InvalidBearerErr struct {
	Message string
}

func (InvalidBearerErr) As

func (i InvalidBearerErr) As(target interface{}) bool

func (InvalidBearerErr) Error

func (i InvalidBearerErr) Error() string

type InvalidTokenErr

type InvalidTokenErr struct{}

func (InvalidTokenErr) As

func (i InvalidTokenErr) As(target interface{}) bool

func (InvalidTokenErr) Error

func (i InvalidTokenErr) Error() string

func (InvalidTokenErr) Is

func (i InvalidTokenErr) Is(err error) bool

type JwtClaims

type JwtClaims struct {
	Name  string `json:"name"`
	Email string `json:"email"`
	Image string `json:"image"`
	jwt.StandardClaims
}

type JwtTokenHandler

type JwtTokenHandler interface {
	Sign(user SignUserInput) (*string, error)
	Valid(jwtToken string) (bool, *jwt.Token, error)
}

func NewJwtTokenHandler

func NewJwtTokenHandler(config cfg.Config, name string) JwtTokenHandler

func NewJwtTokenHandlerWithInterfaces

func NewJwtTokenHandlerWithInterfaces(settings JwtTokenHandlerSettings) JwtTokenHandler

type JwtTokenHandlerSettings

type JwtTokenHandlerSettings struct {
	SigningSecret  string        `cfg:"signingSecret" validate:"min=8"`
	Issuer         string        `cfg:"issuer" validate:"required"`
	ExpireDuration time.Duration `cfg:"expireDuration" default:"15m" validate:"min=60000000000"`
}

type ModelProvider

type ModelProvider func() TokenBearer

type SignUserInput

type SignUserInput struct {
	Name  string
	Email string
	Image string
}

type Subject

type Subject struct {
	Name            string
	Anonymous       bool
	AuthenticatedBy string
	Attributes      map[string]interface{}
}

func GetSubject

func GetSubject(ctx context.Context) *Subject

type TokenBearer

type TokenBearer interface {
	GetToken() string
}

type TokenBearerProvider

type TokenBearerProvider func(ctx context.Context, key string, token string) (TokenBearer, error)

func ProvideTokenBearerFromDdb

func ProvideTokenBearerFromDdb(repo ddb.Repository, getModel ModelProvider) TokenBearerProvider

func ProvideTokenBearerFromGetter

func ProvideTokenBearerFromGetter(getter Getter, getModel ModelProvider) TokenBearerProvider

type TokenInfoProvider

type TokenInfoProvider interface {
	GetTokenInfo(string) (*oauth2.Tokeninfo, error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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