Documentation
¶
Overview ¶
Package oauth provides a built-in OAuth2/OIDC authorization server for SMART on FHIR.
Hosts can mount oauth.Server alongside pkg/http FHIR handlers to issue and validate access tokens without an external authorization server. The server exposes:
- /.well-known/openid-configuration
- /.well-known/smart-configuration
- /oauth/authorize
- /oauth/token
- /oauth/jwks
- /oauth/register
Durable state is provided by pkg/oauth/store (Postgres or SQLite). haistack serve wires builtin OAuth via runtime.WithBuiltinOAuth when oauth.enabled is true.
Index ¶
- Constants
- Variables
- func ApplyProductionDefaults(cfg *Config) error
- func CombineHandlers(primary http.Handler, extras ...http.Handler) http.Handler
- func DecryptSigningKeyPEM(ciphertext, nonce, secret string) ([]byte, error)
- func DefaultRegisteredClientScopes() []string
- func EncryptSigningKeyPEM(pem []byte, secret string) (ciphertext string, nonce string, err error)
- func EntryIssuerMatches(entryIssuer, serverIssuer string) bool
- func HashLoginPassword(password string) (string, error)
- func IssuerScopedKey(issuer, id string) (string, error)
- func NormalizeIssuerURL(issuer string) string
- func PrepareClientSecret(client *Client) error
- func RequireBoundIssuer(issuer string) (string, error)
- func RequireSigningKeyEncryptionSecret() error
- func RunPendingAuthorizationCleanup(ctx context.Context, store AuthorizationStore, interval time.Duration)
- func SaveKeySetToPEM(path string, key *KeySet) error
- func ServeConsentPage(w http.ResponseWriter, req AuthorizationRequest, csrfToken string)
- func SigningKeyEncryptionSecret() string
- func SigningKeyRotateOnStartup() bool
- func StartPendingAuthorizationCleanup(ctx context.Context, store AuthorizationStore, interval time.Duration)
- func ValidateProductionIssuer(issuer string) error
- func ValidateRedirectURI(raw string) error
- type AuthorizationCode
- type AuthorizationRequest
- type AuthorizationStore
- type BcryptLoginUsers
- type Client
- type ClientRegistry
- type ClientStore
- type Config
- type ConsentHandler
- type ConsentHandlerFunc
- type IntrospectionResponse
- type IssuerScopedClientRegistry
- type KeySet
- type LaunchContext
- type LaunchResolver
- type LaunchResolverFunc
- type LoginUserStore
- type MemoryAuthorizationStore
- func (s *MemoryAuthorizationStore) ConsumeAuthorizationCode(issuer, code string) (AuthorizationCode, bool)
- func (s *MemoryAuthorizationStore) ConsumePendingAuthorization(issuer, id string) (PendingAuthorization, bool)
- func (s *MemoryAuthorizationStore) ConsumeRefreshToken(issuer, token string) (RefreshTokenEntry, bool)
- func (s *MemoryAuthorizationStore) DeleteRefreshTokenForClient(issuer, token, clientID string) bool
- func (s *MemoryAuthorizationStore) GetPendingAuthorization(issuer, id string) (PendingAuthorization, bool)
- func (s *MemoryAuthorizationStore) LookupRefreshToken(issuer, token string) (RefreshTokenEntry, bool)
- func (s *MemoryAuthorizationStore) PurgeExpiredPendingAuthorizations() int
- func (s *MemoryAuthorizationStore) SaveAuthorizationCode(code string, entry AuthorizationCode) error
- func (s *MemoryAuthorizationStore) SavePendingAuthorization(id string, entry PendingAuthorization) error
- func (s *MemoryAuthorizationStore) SaveRefreshToken(token string, entry RefreshTokenEntry) error
- type MemoryTokenRevocationStore
- type MultiTenantBearerAuth
- func (m MultiTenantBearerAuth) BearerConfigForRequest(r *http.Request) (smart.BearerAuthConfig, error)
- func (m MultiTenantBearerAuth) BundleResolver() hahttp.AuthBundleResolver
- func (m MultiTenantBearerAuth) PrincipalResolver() hahttp.PrincipalResolver
- func (m MultiTenantBearerAuth) ResolveBearerTokenCached(ctx context.Context, r *http.Request) (smart.BearerAuthResult, error)
- type MultiTenantConfig
- type MultiTenantServer
- type PendingAuthorization
- type RateLimitConfig
- type RateLimitStore
- type RefreshTokenEntry
- type Server
- func (s *Server) BackendAssertionAuthConfig(adapter *smart.AuthAdapter) smart.BackendAssertionAuthConfig
- func (s *Server) BearerAuthConfig(adapter *smart.AuthAdapter) smart.BearerAuthConfig
- func (s *Server) Handler() http.Handler
- func (s *Server) IntrospectToken(token, tokenTypeHint string) IntrospectionResponse
- func (s *Server) Issuer() string
- func (s *Server) RegisterClient(client Client) error
- func (s *Server) SigningPrivateKey() *rsa.PrivateKey
- type SessionAuthConfig
- type SessionUserAuthenticator
- type SigningKeyPaths
- type TenantIssuerConfig
- type TenantRegistry
- type TokenRevocationStore
- type TokenStoredeprecated
- type UserAuthenticator
- type UserAuthenticatorFunc
- type UserIdentity
Constants ¶
const ( AuthMethodClientSecretPost = "client_secret_post" AuthMethodClientSecretBasic = "client_secret_basic" AuthMethodPrivateKeyJWT = "private_key_jwt" AuthMethodNone = "none" )
const DefaultPendingAuthorizationCleanupInterval = 5 * time.Minute
DefaultPendingAuthorizationCleanupInterval is the recommended background purge interval for SQL-backed consent sessions in production-like hosts.
const LoginUsersEnv = "OAUTH_LOGIN_USERS"
LoginUsersEnv is the production username/password directory. Entries are `username:password` or `username:$2a$...` separated by newlines or `;`.
Variables ¶
var ErrInvalidConfig = errors.New("oauth: invalid config")
ErrInvalidConfig indicates invalid OAuth server configuration.
var ErrInvalidScope = errors.New("oauth: invalid scope")
ErrInvalidScope indicates a requested OAuth scope is not allowed.
Functions ¶
func ApplyProductionDefaults ¶
ApplyProductionDefaults applies safer OAuth defaults for production-like hosts. Call after store wiring and before NewServer.
func CombineHandlers ¶
CombineHandlers mounts multiple OAuth handlers on one mux by path prefix.
func DecryptSigningKeyPEM ¶
DecryptSigningKeyPEM decrypts a PEM-encoded private key encrypted with EncryptSigningKeyPEM.
func DefaultRegisteredClientScopes ¶
func DefaultRegisteredClientScopes() []string
DefaultRegisteredClientScopes is the SMART scope allow-list applied to dynamically registered clients that omit scope, and the maximum scopes DCR may request.
func EncryptSigningKeyPEM ¶
EncryptSigningKeyPEM encrypts a PEM-encoded private key with AES-GCM.
func EntryIssuerMatches ¶
EntryIssuerMatches reports whether a stored row belongs to serverIssuer. Both issuers must be non-empty and equal after normalization.
func HashLoginPassword ¶
HashLoginPassword returns a bcrypt hash of password.
func IssuerScopedKey ¶
IssuerScopedKey returns a map key unique to one issuer and token/code/session id.
func NormalizeIssuerURL ¶
NormalizeIssuerURL trims and removes a trailing slash from an issuer URL.
func PrepareClientSecret ¶
PrepareClientSecret hashes plaintext client secrets before persistence.
func RequireBoundIssuer ¶
RequireBoundIssuer returns a normalized issuer or an error when missing.
func RequireSigningKeyEncryptionSecret ¶
func RequireSigningKeyEncryptionSecret() error
RequireSigningKeyEncryptionSecret returns an error when secret is empty.
func RunPendingAuthorizationCleanup ¶
func RunPendingAuthorizationCleanup(ctx context.Context, store AuthorizationStore, interval time.Duration)
RunPendingAuthorizationCleanup periodically purges expired consent sessions until ctx is cancelled.
func SaveKeySetToPEM ¶
SaveKeySetToPEM writes an RSA private key to path, creating parent directories as needed.
func ServeConsentPage ¶
func ServeConsentPage(w http.ResponseWriter, req AuthorizationRequest, csrfToken string)
ServeConsentPage writes a minimal HTML consent form for pending authorization requests.
func SigningKeyEncryptionSecret ¶
func SigningKeyEncryptionSecret() string
SigningKeyEncryptionSecret returns the configured signing-key encryption secret.
func SigningKeyRotateOnStartup ¶
func SigningKeyRotateOnStartup() bool
SigningKeyRotateOnStartup reports whether signing keys should rotate on process start.
func StartPendingAuthorizationCleanup ¶
func StartPendingAuthorizationCleanup(ctx context.Context, store AuthorizationStore, interval time.Duration)
StartPendingAuthorizationCleanup runs RunPendingAuthorizationCleanup in a background goroutine.
func ValidateProductionIssuer ¶
ValidateProductionIssuer requires a non-empty https issuer URL.
func ValidateRedirectURI ¶
ValidateRedirectURI checks redirect URIs allowed for dynamic client registration.
Types ¶
type AuthorizationCode ¶
type AuthorizationCode struct {
Issuer string `json:"issuer,omitempty"`
ClientID string `json:"clientId"`
RedirectURI string `json:"redirectUri"`
Scope string `json:"scope"`
Patient string `json:"patient,omitempty"`
Encounter string `json:"encounter,omitempty"`
Subject string `json:"subject,omitempty"`
FHIRUser string `json:"fhirUser,omitempty"`
Challenge string `json:"challenge,omitempty"`
Method string `json:"method,omitempty"`
ExpiresAt time.Time `json:"expiresAt"`
}
AuthorizationCode is a short-lived authorization code entry.
type AuthorizationRequest ¶
type AuthorizationRequest struct {
ClientID string
RedirectURI string
Scope string
State string
Patient string
Encounter string
Subject string
FHIRUser string
Launch string
CodeChallenge string
CodeChallengeMethod string
}
AuthorizationRequest captures parameters from the authorize endpoint.
type AuthorizationStore ¶
type AuthorizationStore interface {
SaveAuthorizationCode(code string, entry AuthorizationCode) error
ConsumeAuthorizationCode(issuer, code string) (AuthorizationCode, bool)
SaveRefreshToken(token string, entry RefreshTokenEntry) error
ConsumeRefreshToken(issuer, token string) (RefreshTokenEntry, bool)
LookupRefreshToken(issuer, token string) (RefreshTokenEntry, bool)
SavePendingAuthorization(id string, entry PendingAuthorization) error
GetPendingAuthorization(issuer, id string) (PendingAuthorization, bool)
ConsumePendingAuthorization(issuer, id string) (PendingAuthorization, bool)
DeleteRefreshTokenForClient(issuer, token, clientID string) bool
// PurgeExpiredPendingAuthorizations removes expired consent sessions.
PurgeExpiredPendingAuthorizations() int
}
AuthorizationStore persists authorization codes, refresh tokens, and pending authorization sessions. Production deployments use pkg/oauth/store (SQLite or Postgres).
type BcryptLoginUsers ¶
type BcryptLoginUsers struct {
// contains filtered or unexported fields
}
BcryptLoginUsers is a static username → bcrypt-hash directory.
func ParsePasswordUsers ¶
func ParsePasswordUsers(raw string) (*BcryptLoginUsers, error)
ParsePasswordUsers parses OAUTH_LOGIN_USERS contents.
func PasswordUsersFromEnv ¶
func PasswordUsersFromEnv() (*BcryptLoginUsers, error)
PasswordUsersFromEnv loads OAUTH_LOGIN_USERS.
func RequirePasswordUsersFromEnv ¶
func RequirePasswordUsersFromEnv() (*BcryptLoginUsers, error)
RequirePasswordUsersFromEnv requires a non-empty production login directory.
func (*BcryptLoginUsers) Verify ¶
func (u *BcryptLoginUsers) Verify(username, password string) (UserIdentity, bool)
Verify implements LoginUserStore.
type Client ¶
type Client struct {
ClientID string
ClientSecret string
ClientSecretHash string
ClientName string
RedirectURIs []string
GrantTypes []string
ResponseTypes []string
Scopes []string
TokenEndpointAuthMethod string
PublicKeyPEM string
KeyID string
Algorithm string
}
Client describes a registered OAuth client.
func (Client) ToBackendClient ¶
func (c Client) ToBackendClient() smart.BackendClient
ToBackendClient converts client key metadata for backend assertion validation.
type ClientRegistry ¶
ClientRegistry stores registered OAuth clients.
type ClientStore ¶
type ClientStore struct {
// contains filtered or unexported fields
}
ClientStore stores registered OAuth clients in memory.
func NewClientStore ¶
func NewClientStore() *ClientStore
NewClientStore constructs an empty client store.
func (*ClientStore) ForIssuer ¶
func (s *ClientStore) ForIssuer(string) ClientRegistry
ForIssuer returns an empty in-memory registry so tenants do not share clients.
func (*ClientStore) Get ¶
func (s *ClientStore) Get(clientID string) (Client, bool)
Get returns a registered client.
func (*ClientStore) Register ¶
func (s *ClientStore) Register(client Client) error
Register adds or replaces a client.
type Config ¶
type Config struct {
Issuer string
FHIRAudience string
SigningKey *KeySet
Clients ClientRegistry
AuthorizationStore AuthorizationStore
ReplayStore smart.ReplayStore
RevocationStore TokenRevocationStore
AccessTokenTTL time.Duration
RefreshTokenTTL time.Duration
AuthCodeTTL time.Duration
Now func() time.Time
// ConsentHandler approves authorization requests. When nil and AutoApprove is false,
// the authorize endpoint rejects requests.
ConsentHandler ConsentHandler
// AutoApprove issues authorization codes without consent review. Use only in tests.
AutoApprove bool
// RequireConsentForm redirects to a built-in HTML consent page before issuing codes.
RequireConsentForm bool
// AllowDynamicRegistration enables POST /oauth/register. Disabled by default.
AllowDynamicRegistration bool
// RegistrationAccessToken protects POST /oauth/register when set.
RegistrationAccessToken string
// LaunchResolver resolves EHR launch tokens for /oauth/launch and authorize.
LaunchResolver LaunchResolver
// UserAuthenticator identifies the end user approving access in production flows.
UserAuthenticator UserAuthenticator
// LoginPath redirects unauthenticated authorize requests when UserAuthenticator is set.
LoginPath string
// RateLimit configures token and registration endpoint rate limits.
RateLimit RateLimitConfig
// TokenRateLimiter overrides the default in-memory token endpoint limiter.
TokenRateLimiter RateLimitStore
// RegisterRateLimiter overrides the default in-memory registration limiter.
RegisterRateLimiter RateLimitStore
// VerificationKeys are additional public keys exposed via JWKS (for rotation).
VerificationKeys []*KeySet
// RequirePKCEForAllClients requires code_challenge for every client at authorize.
RequirePKCEForAllClients bool
// RegisteredClientScopes limits scopes for dynamic client registration.
RegisteredClientScopes []string
}
Config configures a built-in OAuth2/OIDC authorization server.
type ConsentHandler ¶
type ConsentHandler interface {
Approve(ctx context.Context, req AuthorizationRequest) (bool, error)
}
ConsentHandler approves or denies authorization requests before codes are issued. When nil, the server auto-approves (development mode only).
func AutoApproveConsentHandler ¶
func AutoApproveConsentHandler() ConsentHandler
AutoApproveConsentHandler always approves authorization requests.
type ConsentHandlerFunc ¶
type ConsentHandlerFunc func(ctx context.Context, req AuthorizationRequest) (bool, error)
ConsentHandlerFunc adapts a function to ConsentHandler.
func (ConsentHandlerFunc) Approve ¶
func (f ConsentHandlerFunc) Approve(ctx context.Context, req AuthorizationRequest) (bool, error)
Approve implements ConsentHandler.
type IntrospectionResponse ¶
type IntrospectionResponse struct {
Active bool `json:"active"`
Scope string `json:"scope,omitempty"`
ClientID string `json:"client_id,omitempty"`
Username string `json:"username,omitempty"`
TokenType string `json:"token_type,omitempty"`
Exp int64 `json:"exp,omitempty"`
Iat int64 `json:"iat,omitempty"`
Sub string `json:"sub,omitempty"`
Aud string `json:"aud,omitempty"`
Iss string `json:"iss,omitempty"`
JTI string `json:"jti,omitempty"`
Patient string `json:"patient,omitempty"`
FHIRUser string `json:"fhirUser,omitempty"`
Tenant string `json:"tenant,omitempty"`
}
IntrospectionResponse is the RFC 7662 token introspection payload.
type IssuerScopedClientRegistry ¶
type IssuerScopedClientRegistry interface {
ForIssuer(issuer string) ClientRegistry
}
IssuerScopedClientRegistry can return an issuer-isolated client registry view.
type KeySet ¶
type KeySet struct {
PrivateKey *rsa.PrivateKey
KeyID string
Algorithm string
// RetireAt is when a rotated key leaves JWKS and verification. Zero means active.
RetireAt time.Time
}
KeySet holds signing keys exposed through JWKS.
func LoadKeySetFromPEM ¶
LoadKeySetFromPEM loads an RSA signing key from a PKCS#8 or PKCS#1 PEM file.
func LoadOrCreateSigningKey ¶
LoadOrCreateSigningKey loads a PEM signing key from path or generates and persists one.
func LoadSigningKey ¶
func LoadSigningKey(paths SigningKeyPaths) (*KeySet, error)
LoadSigningKey loads a persistent signing key when the PEM file exists.
func (*KeySet) PublicKeyPEM ¶
PublicKeyPEM returns PKIX PEM for the public key.
type LaunchContext ¶
LaunchContext is the SMART EHR launch context returned from /oauth/launch.
type LaunchResolver ¶
type LaunchResolver interface {
ResolveLaunch(ctx context.Context, launch string, iss string) (LaunchContext, error)
}
LaunchResolver resolves a launch token into SMART launch context.
func StaticLaunchResolver ¶
func StaticLaunchResolver(ctx LaunchContext) LaunchResolver
StaticLaunchResolver returns fixed launch context for demos and tests.
type LaunchResolverFunc ¶
LaunchResolverFunc adapts a function to LaunchResolver.
func (LaunchResolverFunc) ResolveLaunch ¶
func (f LaunchResolverFunc) ResolveLaunch(ctx context.Context, launch string, iss string) (LaunchContext, error)
type LoginUserStore ¶
type LoginUserStore interface {
Verify(username, password string) (UserIdentity, bool)
}
LoginUserStore verifies end-user passwords for session login.
type MemoryAuthorizationStore ¶
type MemoryAuthorizationStore struct {
Now func() time.Time
// contains filtered or unexported fields
}
MemoryAuthorizationStore is a process-local AuthorizationStore.
func NewMemoryAuthorizationStore ¶
func NewMemoryAuthorizationStore() *MemoryAuthorizationStore
NewMemoryAuthorizationStore constructs an in-memory authorization store.
func NewTokenStore ¶
func NewTokenStore() *MemoryAuthorizationStore
NewTokenStore constructs an in-memory authorization store.
func (*MemoryAuthorizationStore) ConsumeAuthorizationCode ¶
func (s *MemoryAuthorizationStore) ConsumeAuthorizationCode(issuer, code string) (AuthorizationCode, bool)
func (*MemoryAuthorizationStore) ConsumePendingAuthorization ¶
func (s *MemoryAuthorizationStore) ConsumePendingAuthorization(issuer, id string) (PendingAuthorization, bool)
func (*MemoryAuthorizationStore) ConsumeRefreshToken ¶
func (s *MemoryAuthorizationStore) ConsumeRefreshToken(issuer, token string) (RefreshTokenEntry, bool)
func (*MemoryAuthorizationStore) DeleteRefreshTokenForClient ¶
func (s *MemoryAuthorizationStore) DeleteRefreshTokenForClient(issuer, token, clientID string) bool
func (*MemoryAuthorizationStore) GetPendingAuthorization ¶
func (s *MemoryAuthorizationStore) GetPendingAuthorization(issuer, id string) (PendingAuthorization, bool)
func (*MemoryAuthorizationStore) LookupRefreshToken ¶
func (s *MemoryAuthorizationStore) LookupRefreshToken(issuer, token string) (RefreshTokenEntry, bool)
func (*MemoryAuthorizationStore) PurgeExpiredPendingAuthorizations ¶
func (s *MemoryAuthorizationStore) PurgeExpiredPendingAuthorizations() int
func (*MemoryAuthorizationStore) SaveAuthorizationCode ¶
func (s *MemoryAuthorizationStore) SaveAuthorizationCode(code string, entry AuthorizationCode) error
func (*MemoryAuthorizationStore) SavePendingAuthorization ¶
func (s *MemoryAuthorizationStore) SavePendingAuthorization(id string, entry PendingAuthorization) error
func (*MemoryAuthorizationStore) SaveRefreshToken ¶
func (s *MemoryAuthorizationStore) SaveRefreshToken(token string, entry RefreshTokenEntry) error
type MemoryTokenRevocationStore ¶
type MemoryTokenRevocationStore struct {
Now func() time.Time
// contains filtered or unexported fields
}
MemoryTokenRevocationStore is a process-local revocation denylist.
func NewMemoryTokenRevocationStore ¶
func NewMemoryTokenRevocationStore() *MemoryTokenRevocationStore
NewMemoryTokenRevocationStore constructs an in-memory revocation store.
func (*MemoryTokenRevocationStore) IsRevoked ¶
func (s *MemoryTokenRevocationStore) IsRevoked(jti string) bool
type MultiTenantBearerAuth ¶
type MultiTenantBearerAuth struct {
Base *Server
Tenants *MultiTenantServer
Adapter *smart.AuthAdapter
}
MultiTenantBearerAuth validates Bearer tokens issued by the base OAuth server or any registered tenant issuer.
func (MultiTenantBearerAuth) BearerConfigForRequest ¶
func (m MultiTenantBearerAuth) BearerConfigForRequest(r *http.Request) (smart.BearerAuthConfig, error)
BearerConfigForRequest selects the bearer validation config for the request token issuer.
func (MultiTenantBearerAuth) BundleResolver ¶
func (m MultiTenantBearerAuth) BundleResolver() hahttp.AuthBundleResolver
BundleResolver returns an HTTP auth bundle resolver for multi-tenant OAuth tokens.
func (MultiTenantBearerAuth) PrincipalResolver ¶
func (m MultiTenantBearerAuth) PrincipalResolver() hahttp.PrincipalResolver
PrincipalResolver returns an HTTP principal resolver for multi-tenant OAuth tokens.
func (MultiTenantBearerAuth) ResolveBearerTokenCached ¶
func (m MultiTenantBearerAuth) ResolveBearerTokenCached(ctx context.Context, r *http.Request) (smart.BearerAuthResult, error)
ResolveBearerTokenCached validates the Bearer token against the matching issuer.
type MultiTenantConfig ¶
type MultiTenantConfig struct {
Base Config
Tenants *TenantRegistry
}
MultiTenantConfig configures a shared OAuth backend with per-tenant issuers.
type MultiTenantServer ¶
type MultiTenantServer struct {
// contains filtered or unexported fields
}
MultiTenantServer hosts OAuth endpoints for multiple tenant issuers.
func NewMultiTenantServer ¶
func NewMultiTenantServer(cfg MultiTenantConfig) (*MultiTenantServer, error)
NewMultiTenantServer validates config and returns a multi-tenant OAuth server.
func (*MultiTenantServer) Handler ¶
func (m *MultiTenantServer) Handler() http.Handler
Handler mounts tenant-scoped routes under /t/{tenantID}/.
func (*MultiTenantServer) LookupByIssuer ¶
func (m *MultiTenantServer) LookupByIssuer(issuer string) (TenantIssuerConfig, error)
LookupByIssuer returns tenant configuration for a token issuer URL.
func (*MultiTenantServer) ServerForTenant ¶
func (m *MultiTenantServer) ServerForTenant(tenantID string) (*Server, error)
ServerForTenant returns a tenant-scoped authorization server view.
type PendingAuthorization ¶
type PendingAuthorization struct {
Issuer string `json:"issuer,omitempty"`
Request AuthorizationRequest `json:"request"`
Subject string `json:"subject,omitempty"`
FHIRUser string `json:"fhirUser,omitempty"`
CSRFToken string `json:"csrfToken,omitempty"`
ExpiresAt time.Time `json:"expiresAt"`
}
PendingAuthorization stores an in-progress authorize/consent/launch session.
type RateLimitConfig ¶
type RateLimitConfig struct {
TokenRequests int
RegisterRequests int
LoginRequests int
LoginIPRequests int
Window time.Duration
}
RateLimitConfig configures OAuth endpoint rate limits.
type RateLimitStore ¶
type RateLimitStore interface {
Allow(ctx context.Context, endpoint, bucketKey string, limit int, window time.Duration, now time.Time) (bool, error)
}
RateLimitStore persists or tracks OAuth endpoint request counters.
type RefreshTokenEntry ¶
type RefreshTokenEntry struct {
Issuer string `json:"issuer,omitempty"`
ClientID string `json:"clientId"`
Scope string `json:"scope"`
Patient string `json:"patient,omitempty"`
Encounter string `json:"encounter,omitempty"`
Subject string `json:"subject"`
FHIRUser string `json:"fhirUser,omitempty"`
ExpiresAt time.Time `json:"expiresAt"`
}
RefreshTokenEntry stores refresh-token metadata.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is a SMART-compatible OAuth2/OIDC authorization server.
func (*Server) BackendAssertionAuthConfig ¶
func (s *Server) BackendAssertionAuthConfig(adapter *smart.AuthAdapter) smart.BackendAssertionAuthConfig
BackendAssertionAuthConfig validates backend client assertions for registered clients.
func (*Server) BearerAuthConfig ¶
func (s *Server) BearerAuthConfig(adapter *smart.AuthAdapter) smart.BearerAuthConfig
BearerAuthConfig returns SMART bearer validation wired to this server's signing and verification keys.
func (*Server) Handler ¶
Handler mounts OAuth/OIDC discovery and protocol endpoints on the issuer prefix.
func (*Server) IntrospectToken ¶
func (s *Server) IntrospectToken(token, tokenTypeHint string) IntrospectionResponse
IntrospectToken validates a token and returns RFC 7662 metadata.
func (*Server) RegisterClient ¶
RegisterClient registers an OAuth client.
func (*Server) SigningPrivateKey ¶
func (s *Server) SigningPrivateKey() *rsa.PrivateKey
SigningPrivateKey returns the RSA private key used to sign access tokens.
type SessionAuthConfig ¶
type SessionAuthConfig struct {
Secret string
TTL time.Duration
Now func() time.Time
Issuer string
CookiePath string
Users LoginUserStore
}
SessionAuthConfig configures signed cookie sessions for production consent login.
type SessionUserAuthenticator ¶
type SessionUserAuthenticator struct {
// contains filtered or unexported fields
}
SessionUserAuthenticator authenticates users from signed session cookies.
func NewSessionUserAuthenticator ¶
func NewSessionUserAuthenticator(cfg SessionAuthConfig) (*SessionUserAuthenticator, error)
NewSessionUserAuthenticator constructs a cookie session authenticator.
func (*SessionUserAuthenticator) AuthenticateUser ¶
func (a *SessionUserAuthenticator) AuthenticateUser(r *http.Request) (UserIdentity, bool)
func (*SessionUserAuthenticator) ForIssuer ¶
func (a *SessionUserAuthenticator) ForIssuer(issuer, cookiePath string) *SessionUserAuthenticator
ForIssuer returns a copy bound to issuer and cookie path (tenant isolation).
func (*SessionUserAuthenticator) SetSession ¶
func (a *SessionUserAuthenticator) SetSession(w http.ResponseWriter, subject string) error
type SigningKeyPaths ¶
SigningKeyPaths names the PEM signing-key fallback on disk. Token, client, replay, and revocation state use pkg/oauth/store (SQLite or Postgres).
func DefaultSigningKeyPaths ¶
func DefaultSigningKeyPaths(stateDir string) SigningKeyPaths
DefaultSigningKeyPaths returns the conventional PEM path and key id under stateDir.
type TenantIssuerConfig ¶
type TenantIssuerConfig struct {
TenantID string
Issuer string
FHIRAudience string
SigningKey *KeySet
Clients ClientRegistry
AutoApprove *bool
ConsentHandler ConsentHandler
UserAuthenticator UserAuthenticator
LoginPath string
}
TenantIssuerConfig describes OAuth issuer settings for one tenant namespace.
type TenantRegistry ¶
type TenantRegistry struct {
// contains filtered or unexported fields
}
TenantRegistry stores per-tenant issuer configuration.
func NewTenantRegistry ¶
func NewTenantRegistry() *TenantRegistry
NewTenantRegistry returns an empty tenant registry.
func (*TenantRegistry) IDs ¶
func (r *TenantRegistry) IDs() []string
IDs returns registered tenant ids.
func (*TenantRegistry) Lookup ¶
func (r *TenantRegistry) Lookup(tenantID string) (TenantIssuerConfig, error)
Lookup returns configuration for a tenant id.
func (*TenantRegistry) LookupByIssuer ¶
func (r *TenantRegistry) LookupByIssuer(issuer string) (TenantIssuerConfig, error)
LookupByIssuer returns tenant configuration matching an OAuth issuer URL.
func (*TenantRegistry) Register ¶
func (r *TenantRegistry) Register(cfg TenantIssuerConfig) error
Register upserts a tenant issuer configuration.
type TokenRevocationStore ¶
type TokenRevocationStore interface {
Revoke(jti string, expiresAt time.Time) error
IsRevoked(jti string) bool
}
TokenRevocationStore records revoked access-token JTIs until natural expiry.
type TokenStore
deprecated
type TokenStore = MemoryAuthorizationStore
Deprecated: use AuthorizationStore via Config.AuthorizationStore. TokenStore remains as a thin alias for tests migrating to AuthorizationStore.
type UserAuthenticator ¶
type UserAuthenticator interface {
AuthenticateUser(r *http.Request) (UserIdentity, bool)
}
UserAuthenticator identifies the human user approving SMART authorization.
func StaticUserAuthenticator ¶
func StaticUserAuthenticator(user UserIdentity) UserAuthenticator
StaticUserAuthenticator returns a fixed user for demos and tests.
type UserAuthenticatorFunc ¶
type UserAuthenticatorFunc func(r *http.Request) (UserIdentity, bool)
UserAuthenticatorFunc adapts a function to UserAuthenticator.
func (UserAuthenticatorFunc) AuthenticateUser ¶
func (f UserAuthenticatorFunc) AuthenticateUser(r *http.Request) (UserIdentity, bool)
type UserIdentity ¶
UserIdentity is an authenticated end-user at the authorization server.
Source Files
¶
- backend_store.go
- client.go
- client_auth.go
- consent.go
- consent_cleanup.go
- doc.go
- errors.go
- handlers.go
- htmlutil.go
- introspect.go
- issuer_binding.go
- jwt.go
- keys.go
- launch.go
- persistent.go
- production.go
- ratelimit.go
- redirect_uri.go
- revocation.go
- revoke.go
- scopes.go
- secrets.go
- server.go
- session_auth.go
- signing_key_crypto.go
- store.go
- tenant.go
- user.go
- wire.go