Skip to content

Commit

Permalink
Migrate the OpenID module to OpenIddict 4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinchalet committed Dec 23, 2022
1 parent 231cb19 commit 48ecaea
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 120 deletions.
4 changes: 2 additions & 2 deletions src/OrchardCore.Build/Dependencies.props
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
<PackageManagement Include="NJsonSchema" Version="10.8.0" />
<PackageManagement Include="NLog.Web.AspNetCore" Version="5.2.0" />
<PackageManagement Include="NodaTime" Version="3.1.6" />
<PackageManagement Include="OpenIddict.AspNetCore" Version="3.1.1" />
<PackageManagement Include="OpenIddict.Core" Version="3.1.1" />
<PackageManagement Include="OpenIddict.AspNetCore" Version="4.0.0" />
<PackageManagement Include="OpenIddict.Core" Version="4.0.0" />
<PackageManagement Include="OrchardCore.Translations.All" Version="1.5.0" />
<PackageManagement Include="PdfPig" Version="0.1.6" />
<PackageManagement Include="Serilog.AspNetCore" Version="6.1.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,34 +75,46 @@ public void Configure(OpenIddictServerOptions options)
options.SigningCredentials.Add(new SigningCredentials(key, SecurityAlgorithms.RsaSha256));
}

// Note: while endpoint paths in OrchardCore are stored as PathString instances,
// OpenIddict uses System.Uri. To ensure the System.Uri instances created from
// a PathString don't represent root-relative URIs (which would break path-based
// multi-tenancy support), the leading '/' that is always present in PathString
// instances is manually removed from the endpoint path before URIs are created.

if (settings.AuthorizationEndpointPath.HasValue)
{
options.AuthorizationEndpointUris.Add(new Uri(settings.AuthorizationEndpointPath.Value, UriKind.Relative));
options.AuthorizationEndpointUris.Add(new Uri(
settings.AuthorizationEndpointPath.ToUriComponent()[1..], UriKind.Relative));
}

if (settings.LogoutEndpointPath.HasValue)
{
options.LogoutEndpointUris.Add(new Uri(settings.LogoutEndpointPath.Value, UriKind.Relative));
options.LogoutEndpointUris.Add(new Uri(
settings.LogoutEndpointPath.ToUriComponent()[1..], UriKind.Relative));
}

if (settings.TokenEndpointPath.HasValue)
{
options.TokenEndpointUris.Add(new Uri(settings.TokenEndpointPath.Value, UriKind.Relative));
options.TokenEndpointUris.Add(new Uri(
settings.TokenEndpointPath.ToUriComponent()[1..], UriKind.Relative));
}

if (settings.UserinfoEndpointPath.HasValue)
{
options.UserinfoEndpointUris.Add(new Uri(settings.UserinfoEndpointPath.Value, UriKind.Relative));
options.UserinfoEndpointUris.Add(new Uri(
settings.UserinfoEndpointPath.ToUriComponent()[1..], UriKind.Relative));
}

if (settings.IntrospectionEndpointPath.HasValue)
{
options.IntrospectionEndpointUris.Add(new Uri(settings.IntrospectionEndpointPath.Value, UriKind.Relative));
options.IntrospectionEndpointUris.Add(new Uri(
settings.IntrospectionEndpointPath.ToUriComponent()[1..], UriKind.Relative));
}

if (settings.RevocationEndpointPath.HasValue)
{
options.RevocationEndpointUris.Add(new Uri(settings.RevocationEndpointPath.Value, UriKind.Relative));
options.RevocationEndpointUris.Add(new Uri(
settings.RevocationEndpointPath.ToUriComponent()[1..], UriKind.Relative));
}

// For now, response types and response modes are not directly
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Microsoft.IdentityModel.Protocols.OpenIdConnect;
using Microsoft.IdentityModel.Tokens;
using OpenIddict.Abstractions;
using OpenIddict.Validation;
using OpenIddict.Validation.AspNetCore;
using OpenIddict.Validation.DataProtection;
Expand Down Expand Up @@ -105,7 +105,7 @@ public void Configure(OpenIddictValidationOptions options)
if (settings.Authority != null)
{
options.Issuer = settings.Authority;
options.MetadataAddress = settings.MetadataAddress;
options.ConfigurationEndpoint = settings.MetadataAddress;
options.Audiences.Add(settings.Audience);

// Note: OpenIddict 3.0 only accepts tokens issued with a non-empty token type (e.g "at+jwt")
Expand Down Expand Up @@ -140,9 +140,9 @@ public void Configure(OpenIddictValidationOptions options)
return;
}
options.Configuration = new OpenIdConnectConfiguration
options.Configuration = new OpenIddictConfiguration
{
Issuer = configuration.Authority?.AbsoluteUri
Issuer = configuration.Authority
};
// Import the signing keys from the OpenID server configuration.
Expand Down
Loading

0 comments on commit 48ecaea

Please sign in to comment.