Documentation
¶
Overview ¶
Package auth provides authentication and authorization middleware for gRPC.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrDecodePEM is returned when the PEM block cannot be decoded. ErrDecodePEM = errors.New("failed to decode PEM block") // ErrNotECDSA is returned when the public key is not ECDSA. ErrNotECDSA = errors.New("public key is not ECDSA") // ErrInvalidToken is returned when the token is not valid. ErrInvalidToken = errors.New("invalid token") // ErrTokenProcessing is returned when the token claims cannot be read. ErrTokenProcessing = errors.New("failed to process token") // ErrMissingUserID is returned when the token does not contain a user ID. ErrMissingUserID = errors.New("missing user ID in token") )
var ( // ErrNilPublicKey is returned when a nil public key is passed to JWKS. ErrNilPublicKey = errors.New("nil public key") // ErrNotP521 is returned when the public key is not on the P-521 curve. ErrNotP521 = errors.New("expected P-521 curve") // ErrUnexpectedKeyLength is returned when the encoded public key has an unexpected length. ErrUnexpectedKeyLength = errors.New("unexpected key length") )
var ( // ErrDecodeKeyData is returned when the private key PEM block cannot be decoded. ErrDecodeKeyData = errors.New("failed to decode key data") // ErrWrongKeyType is returned when the private key is not a PRIVATE KEY block. ErrWrongKeyType = errors.New("key is of the wrong type") )
var ErrMissingOAuthInput = errors.New("auth: missing oauth access input field")
ErrMissingOAuthInput is returned when a required OAuthAccessInput field is empty.
var ErrUserNotFound = errors.New("user not found")
ErrUserNotFound is returned when an update affects no user rows.
Functions ¶
func JWKS ¶
JWKS renders a single-key JWKS for the given P-521 public key. Returns the JSON body, the deterministic kid (sha256 over X||Y, base64url-no-pad), and any error.
func MintOAuthAccess ¶
func MintOAuthAccess(ctx context.Context, in OAuthAccessInput) (string, error)
MintOAuthAccess returns a fresh signed JWT carrying the OAuth-standard iss/sub/aud/scope claims in addition to the existing user_id claim the gRPC interceptor reads.
Types ¶
type Interceptor ¶
type Interceptor struct {
PublicKeyFile string
}
Interceptor holds configuration for gRPC authentication middleware.
func (*Interceptor) Stream ¶
func (i *Interceptor) Stream( srv any, ss grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler, ) error
Stream is the stream middleware that checks authentication.
func (*Interceptor) Unary ¶
func (i *Interceptor) Unary( ctx context.Context, req any, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler, ) (any, error)
Unary is the unary middleware that checks authentication.
type OAuthAccessInput ¶
type OAuthAccessInput struct {
Issuer string
Audience string
Scope string
PrivateKeyFile string
Lifetime time.Duration
UserID uuid.UUID
}
OAuthAccessInput holds the fields used by MintOAuthAccess.
type Session ¶
type Session struct {
Token string
}
Session contains a session token.
type User ¶
type User struct {
CreatedAt time.Time `db:"created_at" json:"created_at"`
UpdatedAt time.Time `db:"updated_at" json:"updated_at"`
Timezone *string `db:"timezone" json:"timezone,omitempty"`
Username string `db:"username" json:"username"`
Password string `db:"-" json:"password"`
HashedPassword []byte `db:"hashed_password"`
ID uuid.UUID `db:"id" json:"id"`
}
User represents a single system user.
func CreateUser ¶
CreateUser adds a new user record to the database and populates the new ID.
func GetUserByID ¶
GetUserByID returns a persisted user given a UUID.