Documentation
¶
Overview ¶
Table espuser-auth-flows (PK flow_id): the TTL'd browser authorization-code flow record, from /oauth2/authorize through OTP login to the issued code (resolved by the by-code GSI at token exchange). Spec: espuser/docs/en/specs/authorize-code-flow.md.
Index ¶
- Variables
- type AuthFlow
- type AuthFlowsDB
- func (db *AuthFlowsDB) ConsumeCode(flowID string) error
- func (db *AuthFlowsDB) CreateFlow(flow *AuthFlow) error
- func (db *AuthFlowsDB) GetFlow(flowID string) (*AuthFlow, error)
- func (db *AuthFlowsDB) GetFlowByCode(code string) (*AuthFlow, error)
- func (db *AuthFlowsDB) IssueCode(flowID, subject string, grantedScope []string, code string) error
- func (db *AuthFlowsDB) SetUpstreamLeg(flowID, provider, upstreamState, upstreamNonce, upstreamPKCEVerifier string) error
Constants ¶
This section is empty.
Variables ¶
var ( ErrFlowNotFound = errors.New("auth flow not found") ErrFlowExpired = errors.New("auth flow expired") )
Functions ¶
This section is empty.
Types ¶
type AuthFlow ¶
type AuthFlow struct {
FlowID string `dynamodbav:"flow_id"`
ClientID string `dynamodbav:"client_id,omitempty"`
RedirectURI string `dynamodbav:"redirect_uri,omitempty"`
RequestedScope []string `dynamodbav:"requested_scope,omitempty"`
State string `dynamodbav:"state,omitempty"`
CodeChallenge string `dynamodbav:"code_challenge,omitempty"`
CodeChallengeMethod string `dynamodbav:"code_challenge_method,omitempty"`
Subject string `dynamodbav:"subject,omitempty"`
GrantedScope []string `dynamodbav:"granted_scope,omitempty"`
Code string `dynamodbav:"code,omitempty"`
ExpiresOn int64 `dynamodbav:"expires_on,omitempty"`
// Our own state/nonce/verifier for the upstream round-trip. Never the client's: reusing the
// downstream values would leak them upstream and break the client-to-code binding.
Provider string `dynamodbav:"provider,omitempty"`
UpstreamState string `dynamodbav:"upstream_state,omitempty"`
UpstreamNonce string `dynamodbav:"upstream_nonce,omitempty"`
UpstreamPKCEVerifier string `dynamodbav:"upstream_pkce_verifier,omitempty"`
// Identity proven by the login leg but not yet persisted, so an abandoned login leaves no user
// row and this PII ages out with the flow's TTL. Only Contact is identity-bearing.
Contact string `dynamodbav:"contact,omitempty"`
PendingClaims map[string]string `dynamodbav:"pending_claims,omitempty"`
}
type AuthFlowsDB ¶
type AuthFlowsDB struct {
espdynamodb.EspDB
}
func NewAuthFlowsDB ¶
func NewAuthFlowsDB(ctx *rmngctx.RmngContext) *AuthFlowsDB
func (*AuthFlowsDB) ConsumeCode ¶
func (db *AuthFlowsDB) ConsumeCode(flowID string) error
ConsumeCode deletes the flow record so the code is single-use. DbDeleteItem carries an item-exists condition, so a concurrent/replayed second exchange fails atomically (only one caller wins) and is denied. (Token revocation on reuse is a separate open item.)
func (*AuthFlowsDB) CreateFlow ¶
func (db *AuthFlowsDB) CreateFlow(flow *AuthFlow) error
func (*AuthFlowsDB) GetFlowByCode ¶
func (db *AuthFlowsDB) GetFlowByCode(code string) (*AuthFlow, error)
GetFlowByCode resolves a CODE record via the by-code GSI at token exchange.
func (*AuthFlowsDB) IssueCode ¶
func (db *AuthFlowsDB) IssueCode(flowID, subject string, grantedScope []string, code string) error
IssueCode is the LOGIN -> CODE transition after OTP login: stamps subject, granted scopes, and the single-use code. The subject is bound only when still unset (login-fixation guard): a flow whose subject is already bound cannot be re-bound to a different user by a second verify.
func (*AuthFlowsDB) SetUpstreamLeg ¶
func (db *AuthFlowsDB) SetUpstreamLeg(flowID, provider, upstreamState, upstreamNonce, upstreamPKCEVerifier string) error
Conditioned on the subject still being unbound: a flow that already resolved a subject must not start a fresh upstream round-trip.