Documentation
¶
Overview ¶
Package auth provides authentication primitives and middleware components. It supports token abstraction, extraction from HTTP/gRPC requests, validation via Firebase, and context injection.
Key components: - Token: Represents an authentication token with claims. - Authenticator: Validates tokens (currently supports Firebase ID tokens). - TokenExtractor: Extracts tokens from requests (HTTP headers or gRPC metadata). - ContextInjector: Injects validated tokens into the context for usage by services.
Index ¶
- Constants
- func FxModule() fx.Option
- func InjectTokenInCtx(ctx context.Context, token Token) context.Context
- func NewBaseAuthenticator[R any](tokenExtractor TokenExtractor[R], contextInjector ContextInjector, ...) *baseAuthenticator[R]
- func NewGrpcAuthenticator(params GrpcAuthenticatorParams) *grpcAuthenticator
- func NewGrpcTokenExtractor() *grpcTokenExtractor
- func NewHTTPTokenExtractor() *httpTokenExtractor
- func NewHttpAuthenticator(tokenExtractor TokenExtractor[*http.Request], contextInjector ContextInjector, ...) *httpAuthenticator
- func NewToken(value string, typ TokenType, claims TokenClaims) (*token, error)
- func NewTokenContextInjector() *tokenContextInjector
- type ContextInjector
- type GrpcAuthenticatorParams
- type HmacCredentials
- type Token
- type TokenClaims
- type TokenExtractor
- type TokenType
Constants ¶
View Source
const ( AuthorizationHeader = "Authorization" BearerPrefix = "Bearer " )
View Source
const ( // SystemAccountID is a fixed UUID for system-internal calls to allow easy identification SystemAccountID = "ffffffff-ffff-ffff-ffff-ffffffffffff" SystemUsername = "system" )
Variables ¶
This section is empty.
Functions ¶
func NewBaseAuthenticator ¶
func NewBaseAuthenticator[R any]( tokenExtractor TokenExtractor[R], contextInjector ContextInjector, firebaseClient firebase.Client, hmacValidator jwt.Validator, ) *baseAuthenticator[R]
func NewGrpcAuthenticator ¶
func NewGrpcAuthenticator(params GrpcAuthenticatorParams) *grpcAuthenticator
func NewGrpcTokenExtractor ¶
func NewGrpcTokenExtractor() *grpcTokenExtractor
func NewHTTPTokenExtractor ¶
func NewHTTPTokenExtractor() *httpTokenExtractor
func NewHttpAuthenticator ¶
func NewHttpAuthenticator( tokenExtractor TokenExtractor[*http.Request], contextInjector ContextInjector, firebaseClient firebase.Client, hmacValidator jwt.Validator, ) *httpAuthenticator
func NewTokenContextInjector ¶
func NewTokenContextInjector() *tokenContextInjector
Types ¶
type ContextInjector ¶
type GrpcAuthenticatorParams ¶
type GrpcAuthenticatorParams struct {
fx.In
TokenExtractor TokenExtractor[metadata.MD]
ContextInjector ContextInjector
FirebaseClient firebase.Client `optional:"true"`
HmacValidator jwt.Validator
}
type HmacCredentials ¶
type HmacCredentials struct {
// contains filtered or unexported fields
}
HmacCredentials implements credentials.PerRPCCredentials
func NewHmacCredentials ¶
func NewHmacCredentials(issuer jwt.Issuer) *HmacCredentials
func (*HmacCredentials) GetRequestMetadata ¶
func (*HmacCredentials) RequireTransportSecurity ¶
func (c *HmacCredentials) RequireTransportSecurity() bool
type Token ¶
type Token interface {
Claims() TokenClaims
Value() string
Type() TokenType
}
func TokenFromCtx ¶
type TokenClaims ¶
type TokenExtractor ¶
Source Files
¶
Click to show internal directories.
Click to hide internal directories.