Skip to content
Merged
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
14 changes: 10 additions & 4 deletions docs/content/auth-flows/refresh-flow.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,17 @@ The refresh endpoint uses the server's `AuthFlowContext`. It obtains the session

For refresh-token input, the resolver checks:

1. The explicit `X-Refresh-Token` header, if present.
2. The configured refresh cookie, when cookie delivery is active.
3. The configured refresh header, when header delivery is active.
Refresh-token input is resolved exclusively from the effective refresh grant delivery configuration.

The explicit header takes precedence. Header values may be supplied with a `Bearer ` prefix, which the resolver strips.
- 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.

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

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

Missing, malformed, or duplicate refresh credentials 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.

Expand Down
8 changes: 6 additions & 2 deletions docs/content/configuration/advanced-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -655,9 +655,13 @@ These interfaces have different responsibilities.
| `ISessionValidator` | Validate the session |
| `IDeviceResolver` | Resolve device information |

The server supports multiple session identifier sources through internal resolvers, including cookies, bearer credentials, headers, and query parameters.
The server resolves authentication credentials through a unified, mode-aware credential resolution mechanism.

The active resolution behavior is controlled by the configured session resolution options.
The effective authentication mode determines the primary credential, while the effective grant delivery configuration determines its transport.

Each grant is resolved exclusively from its configured cookie or request header. Alternative credential sources are not used as fallbacks.

This keeps credential resolution consistent across authentication handlers, session context resolution, validation endpoints, and refresh flows.

### Custom Session Validator

Expand Down
6 changes: 3 additions & 3 deletions docs/content/configuration/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ UltimateAuth
│ └── UAuthServerOptions
│ ├── Core-defined options
│ ├── Authentication mode restrictions
│ ├── Cookie and session resolution
│ ├── Grant delivery and credential resolution
│ ├── Endpoints
│ ├── Hub configuration
│ ├── Credential policies
Expand Down Expand Up @@ -178,7 +178,7 @@ Direct Core configuration is intended for scenarios that explicitly consume `UAu
| `HubDeploymentMode` | Hub deployment arrangement |
| `Hub` | Hub-specific configuration |
| `Cookie` | Authentication cookie behavior |
| `SessionResolution` | Resolving session identifiers from incoming requests |
| `GrantDelivery` | Authentication grant delivery and credential transport |
| `Endpoints` | Server endpoint configuration |
| `CredentialSessionPolicy` | Session handling after credential changes and recovery |
| `ResetCredential` | Credential reset configuration |
Expand Down Expand Up @@ -701,7 +701,7 @@ The server registers validators for areas including:
- Token settings.
- Multi-tenancy.
- User identifiers.
- Session resolution.
- Grant delivery and credential resolution.
- Pagination.

For example, the server validates that:
Expand Down
150 changes: 56 additions & 94 deletions docs/content/configuration/server-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,8 @@ These types are defined in UltimateAuth Core and composed into the server option
| `HubDeploymentMode` | Describe the relationship between UAuthHub and the application |
| `Hub` | Hub integration and flow settings |
| `Cookie` | Cookie names, security attributes, and lifetime behavior |
| `SessionResolution` | Session identifier sources and precedence |
| `GrantDelivery` | Authentication grant delivery and incoming credential resolution |
| `Endpoints` | Endpoint groups and disabled actions |
| `PrimaryCredential` | Primary credential selection for UI and API requests |
| `AuthResponse` | Authentication credential delivery and redirect behavior |
| `CredentialSessionPolicy` | Session invalidation after credential changes |
| `ResetCredential` | Credential recovery code and token settings |
| `Identifiers` | Identifier behavior, normalization, and uniqueness |
Expand Down Expand Up @@ -545,77 +543,56 @@ For example, an application that delegates user provisioning to administrators m

Endpoint exposure is a separate concern from authorization: an exposed endpoint must still enforce the applicable security policy.

## 9. Session Resolution

`options.SessionResolution` controls how incoming requests provide session identifiers.
## 9. Credential Resolution

UltimateAuth supports four resolution sources:
UltimateAuth resolves incoming authentication credentials according to the effective authentication mode and grant delivery configuration.

- Bearer credentials.
- Custom headers.
- Cookies.
- Query parameters.
Each authentication grant has a single configured transport. Credential resolution does not use an ordered list of alternative sources.

### Default Configuration
### Primary Authentication Credential

| Property | Default |
The effective authentication mode determines which credential establishes the authentication identity.

| Authentication mode | Primary credential |
|---|---|
| `EnableBearer` | `true` |
| `EnableHeader` | `true` |
| `EnableCookie` | `true` |
| `EnableQuery` | `true` |
| `HeaderName` | `X-UAuth-Session` |
| `QueryParameterName` | `session_id` |
| PureOpaque | Opaque session credential |
| Hybrid | Opaque session credential |
| SemiHybrid | JWT access token |
| PureJwt | JWT access token |

The default precedence order is:
### Credential Transport

```text
Bearer
Header
Cookie
Query
```
Incoming credentials are resolved from the configured cookie or request header.

### Configure Resolution Sources
- Cookie delivery reads the configured authentication cookie.
- Header delivery reads the effective request header using the expected header format.
- Query-string credential resolution is not supported.
- Missing or invalid credentials do not trigger fallback to another transport.
- Duplicate credential values are rejected.

```csharp
builder.Services.AddUltimateAuthServer(options =>
{
options.SessionResolution.EnableBearer = true;
options.SessionResolution.EnableHeader = false;
options.SessionResolution.EnableCookie = true;
options.SessionResolution.EnableQuery = false;
});
```
Refresh tokens are resolved separately using their own grant delivery configuration.

This example disables custom-header and query-string session resolution.
### Default Request Header Names

### Change Resolution Order
When header delivery is active, the following request header names are used by default:

```csharp
builder.Services.AddUltimateAuthServer(options =>
{
options.SessionResolution.Order =
[
"Cookie",
"Bearer",
"Header",
"Query"
];
});
```
| Grant | Request header |
|---|---|
| Session | `uas` |
| Access token | `Authorization` |
| Refresh token | `uar` |

Resolution order matters when a request contains multiple candidate credentials.
Access tokens are presented using the `Bearer` authorization scheme. Session and refresh token headers follow their configured header formats.

The selected credential must still pass authentication and session validation.
### Configuration Consistency

### Security Recommendation
Active grants must not share the same cookie name, request header name, or response header name within their respective transport namespaces.

Avoid query-string credentials unless the application has a specific, well-understood requirement.
Conflicting effective grant configurations are rejected.

URLs may be recorded in browser history, reverse-proxy logs, analytics systems, and other infrastructure.
See the Grant Delivery section for configuration examples and delivery defaults.

For most browser and API integrations, cookies or authorization headers are preferable.

## 10. Cookie Configuration

Expand Down Expand Up @@ -772,32 +749,22 @@ Hub artifacts support authentication orchestration and should generally be short

Only trusted origins should be included in `AllowedClientOrigins`.

## 13. Primary Credential Policy

`options.PrimaryCredential` controls which credential kind is preferred for UI and API requests.
## 13. Primary Credential Selection

The defaults are:
UltimateAuth determines the primary authentication credential from the effective authentication mode.

| Property | Default |
| Authentication mode | Primary credential |
|---|---|
| `Ui` | `PrimaryTokenKind.Session` |
| `Api` | `PrimaryTokenKind.AccessToken` |

### Example

```csharp
builder.Services.AddUltimateAuthServer(options =>
{
options.PrimaryCredential.Ui = PrimaryTokenKind.Session;
options.PrimaryCredential.Api = PrimaryTokenKind.AccessToken;
});
```
| PureOpaque | Session |
| Hybrid | Session |
| SemiHybrid | JWT access token |
| PureJwt | JWT access token |

This allows UltimateAuth to distinguish between session-oriented browser interactions and access-token-oriented API interactions.
Primary credential selection is not based on request paths, UI/API classification, or the presence of additional authentication headers.

The primary credential policy does not bypass authentication validation.
The effective grant delivery configuration determines how the selected credential is transported.

It determines which credential kind should be preferred within the applicable request-processing rules.
For more information, see [Authentication Modes](/docs/fundamentals/auth-modes).

## 14. Credential Session Policy

Expand Down Expand Up @@ -1194,7 +1161,7 @@ Avoid constructing redirects from unvalidated user-controlled URLs.

UltimateAuth separates credential delivery from navigation behavior.

Credential delivery is configured through `options.GrantDelivery`:
Authentication grant delivery and incoming credential transport are configured through `options.GrantDelivery`:

```csharp
options.GrantDelivery.Default
Expand Down Expand Up @@ -1233,21 +1200,23 @@ An explicit per-grant delivery mode takes precedence over the global delivery de

Only credentials available in the selected authentication mode can be configured for delivery.

### Credential Delivery Versus Request Authentication
### Request and Response Headers

Response headers deliver newly issued credentials to the client.
Request and response headers serve different purposes.

The default credential response header names are:
Response headers deliver newly issued credentials to the client. Request headers present credentials for authentication or refresh.

| Credential | Response Header |
|---|---|
| Session | `uas` |
| Access token | `uat` |
| Refresh token | `uar` |
| Grant | Default response header | Default request header |
|---|---|---|
| Session | `uas` | `uas` |
| Access token | `uat` | `Authorization` |
| Refresh token | `uar` | `uar` |

These response headers must not be confused with the headers used to authenticate subsequent requests.
The access token response header can be customized independently of the incoming `Authorization: Bearer` convention.

For example, the Blazor client receives an access token through the configured response header and sends it on subsequent authenticated requests using `Authorization: Bearer`.
Session and refresh token headers use their configured header names and formats in both directions.

Header names are case-insensitive. Active grants must use distinct header names within each direction.

### Redirect Configuration

Expand Down Expand Up @@ -1448,7 +1417,6 @@ These validators cover areas including:
- PKCE.
- Multi-tenancy.
- Identifier configuration.
- Session resolution.
- Pagination.
- General server configuration.

Expand Down Expand Up @@ -1549,11 +1517,6 @@ builder.Services.AddUltimateAuthServer(options =>
// Identifier login rules
options.LoginIdentifiers.RequireVerificationForEmail = true;

// Session transport
options.SessionResolution.EnableCookie = true;
options.SessionResolution.EnableBearer = true;
options.SessionResolution.EnableQuery = false;

// Endpoint exposure
options.Endpoints.Authentication = true;
options.Endpoints.Session = true;
Expand Down Expand Up @@ -1633,6 +1596,7 @@ Startup validation does not replace testing, infrastructure security, or validat
| `Diagnostics` | Refresh diagnostics |
| `Endpoints` | Endpoint exposure |
| `Events` | Authentication lifecycle callbacks |
| `GrantDelivery` | Grant transport and credential resolution |
| `Hub` | Hub integration |
| `HubDeploymentMode` | Hub deployment topology |
| `Identifiers` | Identifier behavior |
Expand All @@ -1644,10 +1608,8 @@ Startup validation does not replace testing, infrastructure security, or validat
| `OnConfigureEndpoints` | Advanced endpoint customization |
| `Pagination` | Query page limits |
| `Pkce` | PKCE code lifetime |
| `PrimaryCredential` | UI/API primary credential selection |
| `ResetCredential` | Credential recovery rules |
| `Session` | Session expiration and lifecycle |
| `SessionResolution` | Credential source precedence |
| `Token` | Token issuance and lifetime |
| `UserProfile` | Multi-profile capability |

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -545,8 +545,12 @@
private readonly List<TechnicalFeature> SecurityFeatures =
[
new(
"Argon2id Password Hashing",
"Memory-hard credential protection."),
"Flexible Authentication Modes",
"Choose between stateful session-based and stateless JWT authentication with a unified developer experience."),

new(
"Argon2id Password Hashing",
"Memory-hard credential protection."),

new(
"Dummy Password Verification",
Expand Down Expand Up @@ -596,8 +600,12 @@
private readonly List<TechnicalFeature> EngineeringFeatures =
[
new(
"Atomic Operations",
"Coordinated transactional state changes."),
"Atomic Operations",
"Coordinated transactional state changes."),

new(
"Automatic Refresh",
"Proactive renewal, reactive recovery, and coordinated refresh keep authentication seamless without manual token management."),

new(
"Optimistic Concurrency",
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,6 @@
"Level": 0
}
],
"SourceHash": "E337D6157305E084FF8C16F27475CE2F6FB7149B485D85B015C191773D6753BD",
"SourceHash": "B00D328ECEA190C7A99DB1A3711DA30FE21F8B1B010BFE308873463CA39CD404",
"BuilderVersion": "1"
}

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using CodeBeam.UltimateAuth.Sample.UAuthHub.EFCore;
using CodeBeam.UltimateAuth.Sample.UAuthHub.EFCore.Components;
using CodeBeam.UltimateAuth.Server.Extensions;
using CodeBeam.UltimateAuth.Server.Infrastructure;
using Microsoft.EntityFrameworkCore;
using MudBlazor.Services;
using MudExtensions.Services;
Expand All @@ -33,7 +34,7 @@
builder.Services.AddUltimateAuthServer(o => {
//o.AuthMode = UAuthMode.PureJwt;
//o.GrantDelivery.Default = GrantDeliveryMode.Cookie;
o.Cryptography.JwtSigningKey = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes("UltimateAuth-Development-JWT-Signing-Key-2026-Only"));
o.Cryptography.JwtSigningKey = UAuthCryptographyConstants.DevelopmentJwtSigningKey;

o.Diagnostics.EnableRefreshDetails = true;
//o.Session.MaxLifetime = TimeSpan.FromSeconds(32);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using CodeBeam.UltimateAuth.Sample.Shared.Infrastructure;
using CodeBeam.UltimateAuth.Sample.UAuthHub.Components;
using CodeBeam.UltimateAuth.Server.Extensions;
using CodeBeam.UltimateAuth.Server.Infrastructure;
using MudBlazor.Services;
using MudExtensions.Services;
using Scalar.AspNetCore;
Expand All @@ -30,7 +31,7 @@

builder.Services.AddUltimateAuthServer(o => {
o.Token.AccessTokenLifetime = TimeSpan.FromSeconds(30);
o.Cryptography.JwtSigningKey = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes("UltimateAuth-Development-JWT-Signing-Key-2026-Only"));
o.Cryptography.JwtSigningKey = UAuthCryptographyConstants.DevelopmentJwtSigningKey;

o.Diagnostics.EnableRefreshDetails = true;
o.Login.MaxFailedAttempts = 2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
using CodeBeam.UltimateAuth.Sample.Shared.ResourceApi;
using CodeBeam.UltimateAuth.Server.Extensions;
using CodeBeam.UltimateAuth.Users;
using Microsoft.AspNetCore.HttpOverrides;
using Microsoft.EntityFrameworkCore;
using MudBlazor.Services;
using MudExtensions.Services;
Expand Down Expand Up @@ -67,7 +66,6 @@

builder.Services.AddUltimateAuthClientBlazor(o =>
{
//o.AutoRefresh.Interval = TimeSpan.FromSeconds(5);
o.Reauth.Behavior = ReauthBehavior.RaiseEvent;
//o.UAuthStateRefreshMode = UAuthStateRefreshMode.Validate;
});
Expand Down
Loading
Loading