Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions docs/content/auth-flows/login-flow.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ group: auth-flows

Logging in is often described as a simple exchange: verify a password, issue a token, and consider the user authenticated. That description leaves out the part that matters most over time: **what exactly has been established and how can it be managed or revoked?**

UltimateAuth treats login as a **controlled session-establishment flow**. Credential verification is essential, but it is only one stage. A successful login connects an authenticated user to a tenant, a device context, a session hierarchy, and the security state that governs future requests.
UltimateAuth treats login as a controlled authentication-establishment flow.

The central idea is straightforward:
Credential verification is essential, but it is only one stage. A successful login establishes trust in an identity within a tenant and device context, according to the effective authentication mode.

> **Login establishes a session. Tokens, when enabled, are credentials issued in connection with that session—not the session itself.**
> **Login establishes authentication. Surrogates allow that authentication to continue without repeatedly presenting the original credential.**

Session-managed modes also establish the applicable session lineage.

This distinction shapes how UltimateAuth handles device awareness, session continuity, token issuance, revocation, and authentication policy.

Expand All @@ -23,7 +25,7 @@ In a token-centric design, login is frequently treated as the moment a token is
UltimateAuth starts with the authentication lifecycle instead. It separates four responsibilities:

1. **Identity resolution:** determine which user is attempting to authenticate.
2. **Authentication and security evaluation:** verify the credential and decide whether the attempt is allowed.
2. **Surrogate issuance and transport:** issue the applicable tokens and transport them according to the effective authentication mode and application profile.
3. **Session establishment:** create a managed authentication instance in the appropriate device and user context.
4. **Credential delivery:** optionally issue access and refresh tokens and deliver the applicable credentials according to the server mode and application profile.

Expand Down Expand Up @@ -227,13 +229,13 @@ Depending on the effective mode and issuer behavior, an individual token type ma

### 9. Dispatch the login event and deliver the response

Following successful session and optional token issuance, UltimateAuth dispatches a `UserLoggedInContext` event containing the tenant, user key, time, device, and session ID.
The HTTP endpoint delegates surrogate transport to `ISurrogateResponseWriter`.

The HTTP endpoint then delegates credential delivery to `ICredentialResponseWriter`. Session ID, access token, and refresh token are handled as distinct grant kinds. Delivery is resolved using the effective mode, authentication flow, application profile, and server configuration.
Session ID, access token, and refresh token are handled as distinct surrogate kinds. Their effective transports are determined by the authentication mode, flow, application profile, and server configuration.

Depending on configuration, the HTTP response may complete with `200 OK` or a success redirect. A rejected login may produce `401 Unauthorized` or a configured failure redirect.

**Important for v0.1.0:** `TokenResponseMode.Body` is currently unsupported and rejected during response resolution. Do not assume that the HTTP login endpoint returns a JSON object containing the issued tokens. Consult the configured delivery modes and application profile instead.
**Important:** `SurrogateTransport.Body` is currently unsupported. Do not assume that the HTTP login endpoint returns a JSON object containing the issued tokens.

## TryLogin: evaluate without establishing a session

Expand Down Expand Up @@ -302,9 +304,9 @@ Identity + Valid Credential + Security Decision
Ongoing auth lifecycle
```

The session is the managed authentication instance. Tokens, where used, are credentials associated with that instance. They can be issued, refreshed, and validated without redefining what a login means.
A session represents a managed authentication instance where session lineage is used.

This is the shift UltimateAuth is designed to make: **from login as token generation to login as lifecycle-aware session establishment**.
Surrogates represent the authentication data used to continue authenticated interactions. Their issuance and validation depend on the effective authentication mode.

## Key takeaways

Expand Down
16 changes: 9 additions & 7 deletions docs/content/auth-flows/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ AuthFlowContextFactory
- Read tenant, session, and user contexts
- Resolve application profile and effective server options
- Determine effective authentication mode
- Resolve primary token kind and response delivery policy
- Resolve primary surrogate kind and effective transport
- Resolve device context and return URL
- Validate existing session where applicable
- Reject invalid or unresolved tenant
Expand Down Expand Up @@ -105,11 +105,11 @@ The filter initializes the flow context; it does **not**, by itself, validate a
| `ApplicationProfile` | Describes the kind of application interacting with the server. |
| `EffectiveMode` | Determines the authentication model actually in force for this request. |
| `Options` | Supplies the effective server policy. |
| `PrimaryTokenKind` | Identifies the primary credential/token kind for the effective mode. |
| `PrimarySurrogateKind` | Identifies the primary surrogate for the effective authentication mode. |
| `Response` | Describes effective surrogate transport and redirect behavior. |
| `Device` | Carries the resolved device context. |
| `Session` | Carries validated session security context when available. |
| `IsAuthenticated` / `UserKey` | Represent the resolved authentication identity for this request. |
| `Response` | Describes effective credential delivery and redirect behavior. |
| `ReturnUrlInfo` | Carries parsed navigation intent for applicable browser flows. |

The factory rejects unresolved or invalid tenant context and disallowed authentication modes. When a session context is present, it invokes session validation. For session-authoritative modes such as `PureOpaque` and `Hybrid`, that validation also affects the resolved authentication state.
Expand Down Expand Up @@ -167,11 +167,11 @@ This separation helps prevent HTTP transport details from becoming security poli

A successful domain operation and the HTTP response carrying its outcome are different concerns.

`AuthResponseResolver` derives the effective response configuration from the authentication mode, flow type, application profile, and server options. It binds applicable cookie settings and validates the delivery configuration before the endpoint performs the operation.
`AuthResponseResolver` derives the effective response configuration from the authentication mode, flow type, application profile, and server options.

This means a flow can use the same underlying authentication semantics while producing a client-appropriate HTTP outcome—for example, a response with managed cookies or a browser redirect when configured.
It resolves the applicable surrogate transports, binds cookie settings, and validates transport compatibility before the endpoint performs the operation.

**Current implementation note:** `TokenResponseMode.Body` credential delivery is explicitly unsupported by the response resolver. Do not assume that access or refresh credentials are returned in a JSON response body.
**Current implementation note:** `SurrogateTransport.Body` is not supported. Do not assume that access or refresh tokens are returned in a JSON response body.

A redirect is a navigation decision, **not** an authentication or revocation mechanism. It can return a browser to the application after login or logout; the underlying security operation must stand independently of whether the browser follows the redirect.

Expand Down Expand Up @@ -199,6 +199,8 @@ A useful mental model is to distinguish **proof**, **policy**, and **state**:
| Policy | Effective mode, server options, authority decisions | Determines what is permitted. |
| State | User eligibility, credential records, security state, session root/chain/session | Determines the authoritative lifecycle and validity where applicable. |
| Delivery | Cookies, supported response modes, redirect | Communicates the result to the client. |
| Transport | Cookies and HTTP headers | Carries authentication surrogates between applications. |
| Redirect | Navigation behavior | Communicates the navigation outcome to the client. |

A valid-looking token is not, by itself, permission to ignore revocation, tenant boundaries, session state, or mode-specific validation. Conversely, not every authentication mode is built around a persisted session hierarchy. The authoritative checks must match the configured model.

Expand Down Expand Up @@ -241,7 +243,7 @@ This is the larger goal of UltimateAuth's unified model—not to make every auth
- **`AuthFlowContext` resolves tenant, mode, application profile, device, identity/session information, and response policy** before the handler executes.
- **Proof is not the source of truth.** Validation depends on authoritative state and the effective authentication mode.
- **Authority and orchestration are distinct responsibilities.** The exact checks and state transitions vary by flow.
- **Credential delivery and redirects are outcomes**, not substitutes for security decisions.
- **Surrogate transport and redirects are outcomes**, not substitutes for security decisions.
- **Login, refresh, and logout share a model without sharing identical execution paths.**

## Next step
Expand Down
50 changes: 27 additions & 23 deletions docs/content/auth-flows/refresh-flow.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ group: auth-flows

# Refresh Flow

Refresh is how an existing authentication context continues without asking the user to authenticate again. In UltimateAuth, it is not synonymous with issuing a new access token: the operation depends on the active authentication mode and on whether the context is represented by a server-side session, refresh credentials, or both.
Refresh is how an existing authentication context continues without asking the user to authenticate again. In UltimateAuth, it is not synonymous with issuing a new access token: the operation depends on the active authentication mode and on whether the context is represented by a server-side session, refresh token, or both.

A successful refresh preserves the authenticated identity and its continuity. It does **not** prove the user's credentials again, create a new login, or necessarily extend every lifetime associated with the authentication.

Expand All @@ -22,7 +22,7 @@ UltimateAuth distinguishes three related operations:
- **Refresh** attempts to continue an already established context, subject to its current validity and security policies.
- **Reauthentication** establishes trust again when continuation is unavailable or no longer permitted.

This distinction matters for both security and client behavior. A refresh request can fail because a session expired, a refresh credential is invalid or consumed, the device context does not match, or the underlying chain is no longer usable. The client should treat an unsuccessful refresh as a need to authenticate again, not as an invitation to retry the same credential indefinitely.
This distinction matters for both security and client behavior. A refresh request can fail because a session expired, a refresh token is invalid or consumed, the device context does not match, or the underlying chain is no longer usable. The client should treat an unsuccessful refresh as a need to authenticate again, not as an invitation to retry the same credential indefinitely.

## Mode-dependent strategies

Expand All @@ -48,7 +48,7 @@ The refresh operation:
1. Validates the refresh token, tenant, and device binding.
2. Verifies that the token is associated with a valid refresh chain and is not session-bound.
3. Resolves the authenticated user's current identity information and claims.
4. Generates replacement access and refresh credentials.
4. Generates replacement access and refresh tokens.
5. Atomically consumes the previous refresh token and persists its replacement.

The new JWT access token can be validated independently by Resource APIs.
Expand Down Expand Up @@ -91,7 +91,7 @@ A successful **NoOp** is not a failed refresh: the existing state was valid, but

## Refresh-token rotation

Rotation replaces a valid refresh credential while preserving its association with the existing authentication context.
Rotation replaces a valid refresh token while preserving its association with the existing authentication context.

```text
Refresh token
Expand Down Expand Up @@ -155,56 +155,60 @@ A successful refresh does not create a new authentication session.

The session identifier remains metadata and is not delivered as an opaque authentication credential.

An expired access token does not prevent renewal when the refresh credential and its associated session lineage remain valid.
An expired access token does not prevent renewal when the refresh token and its associated session lineage remain valid.

However, a revoked, expired, or otherwise invalid session cannot be renewed through refresh.

Session touch and refresh-token rotation are separate persistence operations. They should not be interpreted as one cross-store transaction.

### PureJwt: session-independent token continuity

PureJwt refresh validates the refresh credential and its associated refresh chain without resolving an authentication session.
PureJwt refresh validates the refresh token and its associated refresh chain without resolving an authentication session.

The previous refresh token is consumed and replaced together with a new JWT access token.

No session root, session chain, or authentication session is created as part of this operation.

Previously issued access tokens remain subject to their own expiration and validation requirements.

## Request resolution and response delivery
## Request Resolution and Response Transport

The refresh endpoint uses the effective `AuthFlowContext` to resolve the authentication mode, tenant, device and available authentication context.
The effective authentication mode determines how authentication continuity is established.

In PureOpaque and Hybrid, the session credential participates in authentication continuation.
In PureOpaque and Hybrid, the session ID participates in authentication continuation.

In SemiHybrid, the refresh credential identifies the associated session lineage, which must be validated authoritatively.
In SemiHybrid, the refresh token identifies the associated session lineage, which must be validated authoritatively.

In PureJwt, continuation is based on the session-independent refresh chain.
PureJwt uses a session-independent refresh chain.

Refresh-token input is resolved exclusively from the effective refresh grant delivery configuration.
Refresh tokens are resolved exclusively from their effective transport configuration.

- When cookie delivery is active, the configured refresh cookie is used.
- When header delivery is active, the configured refresh request header and header format are used.
- When refresh grant delivery is disabled, no refresh credential is resolved.
- When cookie transport is active, the configured refresh cookie is used.
- When header transport is active, the configured request header and header format are used.
- When refresh token transport is disabled, no refresh token is resolved.

The default refresh credential name is `uar` for both cookie and header delivery.
The default refresh token name is `uar` for both cookie and header transport.

The `X-Refresh-Token` header is not an implicit credential source. It is accepted only when explicitly configured as the refresh grant header.
The `X-Refresh-Token` header is not an implicit token source. It is accepted only when explicitly configured.

Missing, malformed, or duplicate refresh credentials are rejected without falling back to another transport.
Missing, malformed, or duplicate refresh tokens are rejected without falling back to another transport.

On success, the endpoint chooses a **primary credential** according to the refresh response policy, rather than automatically writing every credential returned by the flow. The refresh token is written separately when permitted by the response policy and when a replacement exists. Actual cookie/header placement is determined by the effective response configuration and application profile.
On success, the endpoint selects the applicable primary surrogate according to the refresh response policy. A replacement refresh token is written separately when permitted by the policy and when one has been issued.

The HTTP endpoint returns **`204 No Content`** on successful refresh and **`401 Unauthorized`** when continuation fails. Clients should obtain credentials from the configured response delivery mechanism rather than expecting a JSON token payload. When `Diagnostics.EnableRefreshDetails` is enabled, the endpoint also writes the refresh outcome through its diagnostic response writer.
The HTTP endpoint returns **`204 No Content`** on successful refresh and **`401 Unauthorized`** when continuation fails.

Clients obtain newly issued tokens through the effective transport configuration rather than expecting a JSON token payload.

When `Diagnostics.EnableRefreshDetails` is enabled, the endpoint also writes the refresh outcome through its diagnostic response writer.

## Outcomes and client expectations

| Outcome | Meaning | Client interpretation |
| --- | --- | --- |
| `NoOp` | Existing session is valid; no touch was necessary | Continue normally |
| `Touched` | Existing session activity was updated | Continue normally |
| `Rotated` | Refresh token was consumed and replacement credentials issued | Replace stored credentials with the new values |
| `ReauthRequired` | The flow could not safely continue | Stop using the failed refresh credential and require authentication |
| `Rotated` | Refresh token was consumed and replacement surrogates issued | Replace stored surrogates with the new values |
| `ReauthRequired` | The flow could not safely continue | Stop using the failed refresh token and require authentication |

`RefreshFlowResult` also recognizes `Success` as a successful outcome, although the mode-specific branches described above return `NoOp`, `Touched`, `Rotated` or `ReauthRequired`.

Expand Down Expand Up @@ -234,7 +238,7 @@ The useful distinction is not simply *stateful versus stateless*. It is **what m
- `PureOpaque` continues an existing server-side session, with conditional activity updates.
- `Hybrid` requires session validity and successful refresh-token rotation.
- `SemiHybrid` describes JWT renewal with server-managed lifecycle state.
- `PureJwt` rotates refresh credentials through a session-independent refresh chain.
- `PureJwt` rotates refresh tokens through a session-independent refresh chain.

Refresh does not authenticate a user again. It extends the usefulness of an already established authentication context only within the boundaries of the selected mode and configured security policies.

Expand Down
Loading
Loading