security

package
v0.1.13 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package security implements the functions, types, and interfaces for the module.

Package security implements the functions, types, and interfaces for the module.

Package security implements the functions, types, and interfaces for the module.

Package security implements the functions, types, and interfaces for the module.

Package security implements the functions, types, and interfaces for the module.

Package security implements the functions, types, and interfaces for the module.

Index

Constants

View Source
const (
	MetadataAuthZ = "x-metadata-security-authz"
	MetadataAuthN = "x-metadata-security-authn"
)
View Source
const (
	// MetadataSecurityTokenKey is the default token key.
	MetadataSecurityTokenKey = "x-metadata-security-token-key"
	// MetadataSecuritySkipKey is the default skip key.
	MetadataSecuritySkipKey = "x-metadata-security-skip-key"
)
View Source
const (
	StringBoolTrue  = "true"
	StringBoolFalse = "false"
)
View Source
const (
	ErrorCreateOptionNil = errors.String("authenticator middleware create failed: option is nil")
)

Variables

View Source
var (
	ErrInvalidToken  = securityv1.ErrorAuthErrorReasonBearerTokenMissing("bearer token missing")
	ErrInvalidClaims = securityv1.ErrorAuthErrorReasonInvalidClaims("invalid bearer token")
	ErrMissingClaims = securityv1.ErrorAuthErrorReasonInvalidClaims("missing scheme")
	ErrMissingToken  = securityv1.ErrorAuthErrorReasonBearerTokenMissing("bearer token missing")
	ErrInvalidAuth   = securityv1.ErrorAuthErrorReasonUnauthenticated("unauthenticated")
)

Functions

func ClaimFromTokenTypeContext added in v0.1.5

func ClaimFromTokenTypeContext(ctx context.Context, tokenType security.TokenType) (security.Claims, error)

func ClaimsFromContext added in v0.1.0

func ClaimsFromContext(ctx context.Context) security.Claims

func FromMetaData added in v0.1.0

func FromMetaData(key string) func(ctx context.Context) string

func FromMetaDataKey added in v0.1.2

func FromMetaDataKey(ctx context.Context, key string) string

func FromTransportClient added in v0.1.0

func FromTransportClient(authorize string, scheme string) func(ctx context.Context) string

func FromTransportServer added in v0.1.0

func FromTransportServer(authorize string, scheme string) func(ctx context.Context) string

func IsSkipped added in v0.1.0

func IsSkipped(ctx context.Context, key string) bool

func NewAuthN added in v0.1.0

func NewAuthN(cfg *configv1.Security, ss ...OptionSetting) (middleware.Middleware, error)

NewAuthN is a server authenticator middleware.

func NewAuthNClient added in v0.1.0

func NewAuthNClient(cfg *configv1.Security, ss ...OptionSetting) (middleware.Middleware, error)

NewAuthNClient is a client authenticator middleware.

func NewAuthNServer added in v0.1.0

func NewAuthNServer(cfg *configv1.Security, ss ...OptionSetting) (middleware.Middleware, error)

NewAuthNServer is a server authenticator middleware.

func NewAuthZ added in v0.1.5

func NewAuthZ(cfg *configv1.Security, ss ...OptionSetting) (middleware.Middleware, error)

NewAuthZ returns a new server middleware.

func NewAuthZClient added in v0.1.5

func NewAuthZClient(cfg *configv1.Security, ss ...OptionSetting) (middleware.Middleware, error)

NewAuthZClient returns a new server middleware.

func NewAuthZServer added in v0.1.0

func NewAuthZServer(cfg *configv1.Security, ss ...OptionSetting) (middleware.Middleware, error)

NewAuthZServer returns a new server middleware.

func NewClaimsContext added in v0.1.0

func NewClaimsContext(ctx context.Context, claims security.Claims) context.Context

func NewSkipContext added in v0.1.0

func NewSkipContext(ctx context.Context) context.Context

func NewTokenContext added in v0.1.5

func NewTokenContext(ctx context.Context, token string) context.Context

func NewUserClaimsContext added in v0.1.0

func NewUserClaimsContext(ctx context.Context, claims security.UserClaims) context.Context

func SkipFromContext added in v0.1.0

func SkipFromContext(ctx context.Context) bool

func Skipper added in v0.1.5

func Skipper(cfg *configv1.Security, ss ...OptionSetting) (middleware.Middleware, bool)

func TokenFromContext added in v0.1.5

func TokenFromContext(ctx context.Context) string

func TokenFromTypeContext added in v0.1.5

func TokenFromTypeContext(ctx context.Context, tokenType security.TokenType, scheme string) (string, error)

TokenFromTypeContext .

func TokenToTypeContext added in v0.1.5

func TokenToTypeContext(ctx context.Context, tokenType security.TokenType, scheme string, token string) context.Context

TokenToTypeContext .

func UserClaimsFromContext added in v0.1.0

func UserClaimsFromContext(ctx context.Context) security.UserClaims

func UserClaimsFromMetaData added in v0.1.5

func UserClaimsFromMetaData(ctx context.Context, key string) string

func UserClaimsToMetaData added in v0.1.5

func UserClaimsToMetaData(ctx context.Context, key string, value string) context.Context

func WithSkipContextClient added in v0.1.0

func WithSkipContextClient(ctx context.Context, key string) context.Context

func WithSkipContextServer added in v0.1.0

func WithSkipContextServer(ctx context.Context, key string) context.Context

Types

type Option added in v0.1.0

type Option struct {
	// Authorizer is the authorizer used to authorize the request.
	Authorizer security.Authorizer
	// Authenticator is the authenticator used to authenticate the request.
	Authenticator security.Authenticator
	// Serializer is the serializer used to serialize the claims.
	Serializer security.Serializer
	// TokenKey is the key used to store the token in the context.
	TokenKey string
	// Scheme is the scheme used for the authorization header.
	Scheme string
	// HeaderAuthorize is the name of the authorization header.
	HeaderAuthorize string
	// SkipKey is the key used to skip authentication.
	SkipKey string
	// PublicPaths are the public paths that do not require authentication.
	PublicPaths []string
	// TokenParser is the parser used to parse the token from the context.
	TokenParser func(ctx context.Context) string
	// Parser is the parser used to parse the user claims.
	Parser security.UserClaimsParser
	// Skipper is the function used to skip authentication.
	Skipper func(string) bool
}

Option is a struct that contains the settings for the security middleware.

func (*Option) ApplyDefaults added in v0.1.0

func (o *Option) ApplyDefaults()

ApplyDefaults applies the default settings to the option.

func (*Option) ParserUserClaims added in v0.1.5

func (o *Option) ParserUserClaims(ctx context.Context, claims security.Claims) security.UserClaims

ParserUserClaims parses the user claims from the context.

func (*Option) WithConfig added in v0.1.0

func (o *Option) WithConfig(cfg *configv1.Security) *Option

WithConfig applies the configuration to the option.

type OptionSetting added in v0.1.0

type OptionSetting = func(option *Option)

OptionSetting is a function that sets an option.

func WithAuthenticator added in v0.1.0

func WithAuthenticator(authenticator security.Authenticator) OptionSetting

WithAuthenticator sets the authenticator.

func WithAuthorizer added in v0.1.0

func WithAuthorizer(authorizer security.Authorizer) OptionSetting

WithAuthorizer sets the authorizer.

func WithConfig added in v0.1.0

func WithConfig(cfg *configv1.Security) OptionSetting

WithConfig sets the configuration.

func WithSkipKey added in v0.1.0

func WithSkipKey(key string) OptionSetting

WithSkipKey sets the skip key.

func WithSkipper added in v0.1.0

func WithSkipper(paths ...string) OptionSetting

WithSkipper sets the public paths.

func WithTokenKey added in v0.1.0

func WithTokenKey(key string) OptionSetting

WithTokenKey sets the token key.

func WithTokenParser added in v0.1.13

func WithTokenParser(parser func(ctx context.Context) string) OptionSetting

WithTokenParser sets the token parser.

type ResponseWriter added in v0.1.0

type ResponseWriter func(context.Context, security.Claims) (string, error)

ResponseWriter is a function that writes a response to the http.ResponseWriter.

type TokenParser added in v0.1.0

type TokenParser func(context.Context, string) (security.Claims, error)

TokenParser is a function that parses a token from the context.

Jump to

Keyboard shortcuts

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