oauth

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CtxSubjectKey = "auth.subject"
	CtxScopesKey  = "auth.scopes"
)

Variables

This section is empty.

Functions

func BearerAuthMiddleware

func BearerAuthMiddleware(validator TokenValidator, next http.Handler) http.Handler

func ExtractBearer

func ExtractBearer(authHeader string) (string, error)

func HasAllScopes

func HasAllScopes(current []string, required []string) bool

func JoinScopes

func JoinScopes(s []string) string

func RequireScopes

func RequireScopes(required []string, next http.Handler) http.Handler

func SignHS256

func SignHS256(secret []byte, issuer, audience, subject string, scopes []string, ttl time.Duration) (string, time.Time, error)

Types

type AuthConfig

type AuthConfig struct {
	Issuer       string `json:"issuer"`
	Audience     string `json:"audience"`
	HS256Secret  string `json:"hs256_secret"`
	JWKSURL      string `json:"jwks_url"`
	RSAPublicPEM string `json:"rsa_public_pem"`
}

func LoadAuthConfig

func LoadAuthConfig(jsonPath string) (AuthConfig, error)

func LoadAuthConfigFromBytes

func LoadAuthConfigFromBytes(jsonBytes []byte) (AuthConfig, error)

type JWTValidator

type JWTValidator struct {
	HS256Secret      []byte
	RSAPublic        *rsa.PublicKey
	ExpectedIssuer   string
	ExpectedAudience string
}

func (*JWTValidator) Validate

func (v *JWTValidator) Validate(token string) (string, []string, time.Time, error)

type TokenValidator

type TokenValidator interface {
	Validate(token string) (subject string, scopes []string, expiry time.Time, err error)
}

func NewValidatorFromConfig

func NewValidatorFromConfig(cfg AuthConfig) (TokenValidator, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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