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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
- Issue access tokens as signed `RS256` JWTs instead of encrypted JWEs, so clients and resource servers can validate them against the published JWKS (see [#29](https://github.com/BusinessSimulations/dev-oidc-toolkit/issues/29))
- Add `AccessTokenFormat` config option to switch access tokens between `Jwt` and `Opaque` (see [#29](https://github.com/BusinessSimulations/dev-oidc-toolkit/issues/29))
### Breaking Changes

- **Access tokens are no longer encrypted by default**: access tokens were previously JWEs using `RSA-OAEP`, encrypted under a key that was never published, so nothing outside this application could read them. They are now signed `RS256` JWTs with a readable payload, matching Keycloak, Auth0, Okta and Cognito. Anything that relied on access tokens being opaque should set `AccessTokenFormat` to `Opaque`, which returns a random identifier instead. ID tokens are unaffected

## [0.7.0]
- Add `/healthz/live` and `/healthz/ready` healthcheck endpoint (see [#23](https://github.com/BusinessSimulations/dev-oidc-toolkit/issues/23))
Expand Down
49 changes: 49 additions & 0 deletions DevOidcToolkit.Documentation/docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ This is a list of all of the environment variables that can be used to configure
<td>https://fake-issuer.example.com</td>
<td>None (derived from request URL)</td>
</tr>
<tr>
<td>DevOidcToolkit__AccessTokenFormat</td>
<td>The shape of the access tokens issued to clients, either <code>Jwt</code> for a signed, readable JWT or <code>Opaque</code> for a random identifier with no readable payload. See <a href="#access-token-format">Access token format</a>.</td>
<td>Jwt</td>
<td>Jwt</td>
</tr>
<tr>
<td>DevOidcToolkit__Database__SqliteFile</td>
<td>The path to the SQLite database file. When set, data is persisted to this file and survives restarts. When not set, an in-memory database is used and all data is lost on restart.</td>
Expand Down Expand Up @@ -210,6 +216,13 @@ details](#example-json-configuration)).
<td>https://fake-issuer.example.com</td>
<td>None</td>
</tr>
<tr>
<td>AccessTokenFormat</td>
<td>string</td>
<td>The shape of the access tokens issued to clients, either <code>Jwt</code> or <code>Opaque</code>. See <a href="#access-token-format">Access token format</a> for more information.</td>
<td>Jwt</td>
<td>Jwt</td>
</tr>
<tr>
<td>Database</td>
<td>object</td>
Expand Down Expand Up @@ -248,6 +261,42 @@ details](#example-json-configuration)).
</tbody>
</table>

#### Access token format

Production identity providers issue access tokens in one of two shapes, and `AccessTokenFormat` lets you pick which
one to test your client against.

<table>
<thead>
<tr>
<th>Value</th>
<th>Description</th>
<th>Providers that behave this way</th>
</tr>
</thead>
<tbody>
<tr>
<td>Jwt</td>
<td>A signed JWT (<code>RS256</code>), validated against the key published at the <code>jwks_uri</code>. The payload is readable by the client and by any resource server holding the token.</td>
<td>Keycloak, Auth0, Okta, AWS Cognito, Entra ID for custom APIs</td>
</tr>
<tr>
<td>Opaque</td>
<td>A crypto-secure random identifier with no readable payload. The claims are held server side, so the token can only be inspected through the introspection endpoint. Useful for checking that a client treats access tokens as opaque, as the OAuth specification requires.</td>
<td>Google, Entra ID for Microsoft Graph</td>
</tr>
</tbody>
</table>

ID tokens are always signed `RS256` JWTs and are unaffected by this setting, matching the
`id_token_signing_alg_values_supported` value advertised in the discovery document.

!!! warning "Readable access tokens expose their claims"
With the default `Jwt` format, anyone holding an access token can read every claim in it, including the email
address and roles of the user. This is the same trade-off every provider in the list above makes, and it is
appropriate for the fabricated test data Dev OIDC Toolkit serves. Do not point Dev OIDC Toolkit at real user
data.

#### Https

<table>
Expand Down
1 change: 1 addition & 0 deletions DevOidcToolkit.Documentation/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ theme:
extra:
generator: false
markdown_extensions:
- admonition
- pymdownx.highlight:
anchor_linenums: true
line_spans: __span
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
namespace DevOidcToolkit.UnitTests.Infrastructure.Configuration;

using System;
using System.Collections.Generic;

using DevOidcToolkit.Infrastructure.Configuration;

using Microsoft.Extensions.Configuration;

using Xunit;

public class AccessTokenFormatConfigurationTests
{
private static DevOidcToolkitConfiguration Bind(Dictionary<string, string?> values)
{
var configuration = new ConfigurationBuilder()
.AddInMemoryCollection(values)
.Build();

return configuration.GetSection(DevOidcToolkitConfiguration.Position).Get<DevOidcToolkitConfiguration>()
?? new DevOidcToolkitConfiguration();
}

[Fact]
public void DefaultsToJwtWhenNotConfigured()
{
var config = Bind([]);

Assert.Equal(AccessTokenFormat.Jwt, config.AccessTokenFormat);
}

[Theory]
[InlineData("Jwt", AccessTokenFormat.Jwt)]
[InlineData("Opaque", AccessTokenFormat.Opaque)]
[InlineData("opaque", AccessTokenFormat.Opaque)]
public void BindsTheConfiguredFormat(string value, AccessTokenFormat expected)
{
var config = Bind(new Dictionary<string, string?>
{
["DevOidcToolkit:AccessTokenFormat"] = value
});

Assert.Equal(expected, config.AccessTokenFormat);
}

[Fact]
public void ThrowsForAnUnrecognisedFormat()
{
var exception = Record.Exception(() => Bind(new Dictionary<string, string?>
{
["DevOidcToolkit:AccessTokenFormat"] = "RsaOaep"
}));

Assert.NotNull(exception);
}
}
19 changes: 19 additions & 0 deletions DevOidcToolkit/Infrastructure/Configuration/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class DevOidcToolkitConfiguration
public int Port { get; set; } = 80;
public string? Address { get; set; }
public string? Issuer { get; set; }
public AccessTokenFormat AccessTokenFormat { get; set; } = AccessTokenFormat.Jwt;

[ValidateObjectMembers] public List<UserConfiguration> Users { get; set; } = [];
[ValidateObjectMembers] public List<ClientConfiguration> Clients { get; set; } = [];
Expand All @@ -21,6 +22,24 @@ public class DevOidcToolkitConfiguration
[ValidateObjectMembers] public DatabaseConfiguration Database { get; set; } = new DatabaseConfiguration();
}

/// <summary>
/// The shape of the access tokens issued to client applications. Both values mirror behaviour seen in production
/// identity providers, so clients can be tested against either.
/// </summary>
public enum AccessTokenFormat
{
/// <summary>
/// A signed, readable JWT, as issued by Keycloak, Auth0, Okta, Cognito and Entra ID for custom APIs.
/// </summary>
Jwt,

/// <summary>
/// An opaque, crypto-secure random identifier that carries no readable payload, as issued by Google and by
/// Entra ID for Microsoft Graph. Useful for checking that a client treats access tokens as opaque.
/// </summary>
Opaque
}

public class UserConfiguration
{
[Required] public required string Email { get; set; }
Expand Down
1 change: 1 addition & 0 deletions DevOidcToolkit/Pages/Clients.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public async Task<IActionResult> OnPostAsync()
OpenIddictConstants.Permissions.Endpoints.Authorization,
OpenIddictConstants.Permissions.Endpoints.Token,
OpenIddictConstants.Permissions.Endpoints.EndSession,
OpenIddictConstants.Permissions.Endpoints.Introspection,
OpenIddictConstants.Permissions.GrantTypes.AuthorizationCode,
OpenIddictConstants.Permissions.ResponseTypes.Code,
OpenIddictConstants.Permissions.Scopes.Profile,
Expand Down
17 changes: 16 additions & 1 deletion DevOidcToolkit/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,24 @@
options.SetIssuer(new Uri(config.Issuer));
}

// Register the signing and encryption credentials.
// Register the signing and encryption credentials. OpenIddict requires an encryption key to be registered
// whatever the access token format, so this registration must stay even when access tokens are not encrypted.
options.AddEphemeralEncryptionKey()
.AddEphemeralSigningKey();

// OpenIddict encrypts access tokens by default, using a key it deliberately never publishes in the JWKS.
// That suits a resource server running OpenIddict with the same keys, but this toolkit exists to be called
// by arbitrary clients, and no production provider hands third parties a token they cannot open. Issue the
// shape they actually expect instead.
if (config.AccessTokenFormat == AccessTokenFormat.Opaque)
{
options.UseReferenceAccessTokens();
}
else
{
options.DisableAccessTokenEncryption();
}

// Register the ASP.NET Core host and configure the ASP.NET Core options.
options.UseAspNetCore()
.EnableAuthorizationEndpointPassthrough()
Expand Down Expand Up @@ -258,6 +272,7 @@
Permissions.Endpoints.Authorization,
Permissions.Endpoints.Token,
Permissions.Endpoints.EndSession,
Permissions.Endpoints.Introspection,

Permissions.GrantTypes.AuthorizationCode,
Permissions.ResponseTypes.Code,
Expand Down
Loading