Skip to content

refactor: replace IdentityModel with Duende.IdentityModel #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 4, 2025
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
2 changes: 1 addition & 1 deletion src/Context/SendingRequestContext.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Duende Software. All rights reserved.
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.

using IdentityModel.Client;
using Duende.IdentityModel.Client;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Http;

Expand Down
4 changes: 2 additions & 2 deletions src/Context/UpdateClientAssertionContext.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright (c) Duende Software. All rights reserved.
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.

using System;
using IdentityModel.Client;
using Duende.IdentityModel.Client;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Http;
using System;

namespace IdentityModel.AspNetCore.OAuth2Introspection
{
Expand Down
2 changes: 1 addition & 1 deletion src/IdentityModel.AspNetCore.OAuth2Introspection.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="IdentityModel" Version="6.0.0" />
<PackageReference Include="Duende.IdentityModel" Version="7.0.0" />

<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
<PackageReference Include="minver" Version="6.0.0" PrivateAssets="All" />
Expand Down
7 changes: 4 additions & 3 deletions src/Infrastructure/CacheExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Duende Software. All rights reserved.
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.

using Duende.IdentityModel;
using Microsoft.Extensions.Caching.Distributed;
using Microsoft.Extensions.Logging;
using System;
Expand All @@ -19,20 +20,20 @@ internal static class CacheExtensions
private static readonly JsonSerializerOptions Options;

static CacheExtensions()
{
{
Options = new JsonSerializerOptions
{
IgnoreReadOnlyFields = true,
IgnoreReadOnlyProperties = true,
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull
};

Options.Converters.Add(new ClaimConverter());
}

public static async Task<IEnumerable<Claim>> GetClaimsAsync(this IDistributedCache cache, OAuth2IntrospectionOptions options, string token)
{
var cacheKey = options.CacheKeyGenerator(options,token);
var cacheKey = options.CacheKeyGenerator(options, token);
var bytes = await cache.GetAsync(cacheKey).ConfigureAwait(false);

if (bytes == null)
Expand Down
2 changes: 1 addition & 1 deletion src/OAuth2IntrospectionHandler.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Duende Software. All rights reserved.
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.

using IdentityModel.Client;
using Duende.IdentityModel.Client;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Caching.Distributed;
Expand Down
7 changes: 4 additions & 3 deletions src/OAuth2IntrospectionOptions.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// Copyright (c) Duende Software. All rights reserved.
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.

using Duende.IdentityModel;
using Duende.IdentityModel.Client;
using IdentityModel.AspNetCore.OAuth2Introspection.Infrastructure;
using IdentityModel.Client;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Http;
using System;
Expand Down Expand Up @@ -116,7 +117,7 @@ public OAuth2IntrospectionOptions()
/// <summary>
/// Specifies the method how to generate the cache key from the token
/// </summary>
public Func<OAuth2IntrospectionOptions,string, string> CacheKeyGenerator { get; set; } = CacheUtils.CacheKeyFromToken();
public Func<OAuth2IntrospectionOptions, string, string> CacheKeyGenerator { get; set; } = CacheUtils.CacheKeyFromToken();

/// <summary>
/// Specifies the method how to retrieve the token from the HTTP request
Expand All @@ -133,7 +134,7 @@ public OAuth2IntrospectionOptions()
}

internal AsyncLazy<HttpClient> IntrospectionClient { get; set; }

/// <summary>
/// Check that the options are valid. Should throw an exception if things are not ok.
/// </summary>
Expand Down
12 changes: 6 additions & 6 deletions src/PostConfigureOAuth2IntrospectionOptions.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Copyright (c) Duende Software. All rights reserved.
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.

using System;
using System.Net.Http;
using System.Threading.Tasks;
using Duende.IdentityModel.Client;
using IdentityModel.AspNetCore.OAuth2Introspection.Infrastructure;
using IdentityModel.Client;
using Microsoft.Extensions.Caching.Distributed;
using Microsoft.Extensions.Options;
using System;
using System.Net.Http;
using System.Threading.Tasks;

namespace IdentityModel.AspNetCore.OAuth2Introspection
{
Expand All @@ -30,7 +30,7 @@ public void PostConfigure(string name, OAuth2IntrospectionOptions options)
{
throw new ArgumentException("Caching is enabled, but no IDistributedCache is found in the services collection", nameof(_cache));
}

options.IntrospectionClient = new AsyncLazy<HttpClient>(() => InitializeIntrospectionClient(options));
}

Expand All @@ -53,7 +53,7 @@ private async Task<string> GetIntrospectionEndpointFromDiscoveryDocument(OAuth2I
Address = options.Authority,
Policy = options?.DiscoveryPolicy ?? new DiscoveryPolicy()
}).ConfigureAwait(false);

if (disco.IsError)
{
switch (disco.ErrorType)
Expand Down
2 changes: 1 addition & 1 deletion test/Tests/Configuration.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Copyright (c) Duende Software. All rights reserved.
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.

using Duende.IdentityModel.Client;
using FluentAssertions;
using IdentityModel.AspNetCore.OAuth2Introspection;
using IdentityModel.Client;
using System;
using System.Threading.Tasks;
using Tests.Util;
Expand Down
4 changes: 2 additions & 2 deletions test/Tests/Introspection.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright (c) Duende Software. All rights reserved.
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.

using Duende.IdentityModel;
using Duende.IdentityModel.Client;
using FluentAssertions;
using IdentityModel;
using IdentityModel.AspNetCore.OAuth2Introspection;
using IdentityModel.Client;
using Microsoft.AspNetCore.TestHost;
using Microsoft.Extensions.Caching.Distributed;
using Microsoft.Extensions.DependencyInjection;
Expand Down