flows

package
v0.0.19 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package flows serves what Hydra hands over: the consent and logout steps of a browser's OAuth 2.0 flow (hook Consent, event LoggedOut) and the token hook (hook TokenClaims).

Index

Constants

View Source
const (
	DecisionAccept = "accept"
	DecisionReject = "reject"
	DecisionUI     = "ui"
)

Decisions of a consent.

Variables

View Source
var ErrNoChallenge = errors.New("the request carries no challenge from Hydra")

ErrNoChallenge: the browser came without Hydra's challenge.

Functions

This section is empty.

Types

type ConsentGranted

type ConsentGranted struct {
	Subject  string   `json:"subject"`
	ClientID string   `json:"client_id"`
	Scope    []string `json:"scope"`
	// Automatic: granted without asking (trusted or remembered).
	Automatic bool `json:"automatic"`
}

ConsentGranted is a consent given.

type ConsentIn

type ConsentIn struct {
	Subject    string          `json:"subject"`
	ClientID   string          `json:"client_id"`
	ClientName string          `json:"client_name,omitempty"`
	Metadata   json.RawMessage `json:"client_metadata,omitempty"`
	// SkipConsent: the client is trusted (first-party).
	SkipConsent bool `json:"skip_consent"`
	// Remembered: the subject consented to this client before.
	Remembered        bool            `json:"remembered"`
	RequestedScope    []string        `json:"requested_scope"`
	RequestedAudience []string        `json:"requested_audience,omitempty"`
	ACR               string          `json:"acr,omitempty"`
	AMR               []string        `json:"amr,omitempty"`
	LoginContext      json.RawMessage `json:"login_context,omitempty"`
	OIDCContext       json.RawMessage `json:"oidc_context,omitempty"`
}

ConsentIn is a consent Hydra asks for.

type ConsentOut

type ConsentOut struct {
	// Decision is accept, reject or ui; empty: backplane-hydra's default
	// (accept a trusted or remembered client, else the consent UI, else
	// reject).
	Decision string `json:"decision,omitempty" validate:"omitempty,oneof=accept reject ui"`
	// GrantScope defaults to the requested scope.
	GrantScope        []string        `json:"grant_scope,omitempty"`
	GrantAudience     []string        `json:"grant_audience,omitempty"`
	IDTokenClaims     json.RawMessage `json:"id_token_claims,omitempty"`
	AccessTokenClaims json.RawMessage `json:"access_token_claims,omitempty"`
	// Remember the consent; RememberFor seconds (zero: for ever).
	Remember    *bool `json:"remember,omitempty"`
	RememberFor int64 `json:"remember_for,omitempty"`
	// Error and ErrorDescription of a rejection.
	Error            string `json:"error,omitempty"`
	ErrorDescription string `json:"error_description,omitempty"`
}

ConsentOut decides it and adds claims.

type Flows

type Flows struct {
	deps.Component
	// contains filtered or unexported fields
}

Flows declares the hooks and events and serves the browser endpoints and Hydra's token hook.

func New

func New(parent deps.Scope, hydra ory.Client, key string, settings config.Live[overlay.Settings]) *Flows

New declares the hooks and events under parent.

func (*Flows) BindingChanges

func (f *Flows) BindingChanges(ctx context.Context) <-chan struct{}

BindingChanges signals when the bound hooks change.

func (*Flows) Bound

func (f *Flows) Bound(name string) bool

Bound reports whether a hook (short name) is bound.

func (*Flows) Callbacks

func (f *Flows) Callbacks() http.Handler

Callbacks serves Hydra's token hook.

func (*Flows) ConsentRef

func (f *Flows) ConsentRef() hook.Ref[ConsentIn, ConsentOut]

ConsentRef, TokenRef, Granted and LoggedOutRef are the declared refs.

func (*Flows) Granted

func (f *Flows) Granted() event.Ref[ConsentGranted]

Granted is ConsentGranted.

func (*Flows) Hooks

func (f *Flows) Hooks() []string

Hooks are the declared hook names.

func (*Flows) LoggedOutRef

func (f *Flows) LoggedOutRef() event.Ref[LoggedOut]

LoggedOutRef is LoggedOut.

func (*Flows) Public

func (f *Flows) Public() http.Handler

Public serves the browser endpoints Hydra redirects to: /consent and /logout.

func (*Flows) Stats

func (f *Flows) Stats() []Stat

Stats of every point since start.

func (*Flows) TokenRef

func (f *Flows) TokenRef() hook.Ref[TokenIn, TokenOut]

TokenRef is the token hook.

type LoggedOut

type LoggedOut struct {
	Subject  string `json:"subject"`
	SID      string `json:"sid,omitempty"`
	ClientID string `json:"client_id,omitempty"`
}

LoggedOut is a logout through Hydra.

type Stat

type Stat struct {
	Point       string
	Calls       uint64
	Failures    uint64
	LastAt      time.Time
	LastOutcome string
	LastError   string
	LastLatency time.Duration
}

Stat is how one point has been doing since start.

type TokenIn

type TokenIn struct {
	ClientID        string              `json:"client_id"`
	Subject         string              `json:"subject,omitempty"`
	GrantTypes      []string            `json:"grant_types"`
	RequestedScopes []string            `json:"requested_scopes,omitempty"`
	GrantedScopes   []string            `json:"granted_scopes,omitempty"`
	GrantedAudience []string            `json:"granted_audience,omitempty"`
	Payload         map[string][]string `json:"payload,omitempty"          schemapb:"secret=true"`
	// Session is Hydra's session of the token: its current claims.
	Session json.RawMessage `json:"session,omitempty"`
}

TokenIn is a token Hydra is about to issue.

type TokenOut

type TokenOut struct {
	AccessTokenClaims json.RawMessage `json:"access_token_claims,omitempty"`
	IDTokenClaims     json.RawMessage `json:"id_token_claims,omitempty"`
	// Deny refuses the token (access_denied).
	Deny bool `json:"deny,omitempty"`
}

TokenOut replaces the token's extra claims; empty: unchanged.

Jump to

Keyboard shortcuts

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