Skip to content

Commit 34c2675

Browse files
Fix ObjectDisposedException
Fix ObjectDisposedException in the Apple provider when using System.IdentityModel.Tokens.Jwt 5.5.0+. Co-Authored-By: Anthony Yates <[email protected]>
1 parent 6682d78 commit 34c2675

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

Directory.Packages.props

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@
1212
<PackageVersion Include="Microsoft.NetCore.Analyzers" Version="3.0.0" />
1313
<PackageVersion Include="Shouldly" Version="3.0.2" />
1414
<PackageVersion Include="StyleCop.Analyzers" Version="1.1.118" />
15-
16-
<!--
17-
Cannot use later versions (5.5.0+) due to https://github.com/AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet/issues/1302.
18-
-->
1915
<PackageVersion Include="System.IdentityModel.Tokens.Jwt" Version="5.4.0" />
2016
</ItemGroup>
2117

src/AspNet.Security.OAuth.Apple/Internal/DefaultAppleClientSecretGenerator.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ namespace AspNet.Security.OAuth.Apple.Internal
1818
{
1919
internal sealed class DefaultAppleClientSecretGenerator : AppleClientSecretGenerator
2020
{
21+
private static readonly CryptoProviderFactory CryptoProviderFactory = new CryptoProviderFactory()
22+
{
23+
CacheSignatureProviders = false,
24+
};
25+
2126
private readonly ISystemClock _clock;
2227
private readonly ILogger _logger;
2328
private readonly AppleKeyStore _keyStore;
@@ -110,7 +115,13 @@ private static ECDsa CreateAlgorithm(byte[] keyBlob)
110115
private static SigningCredentials CreateSigningCredentials(string keyId, ECDsa algorithm)
111116
{
112117
var key = new ECDsaSecurityKey(algorithm) { KeyId = keyId };
113-
return new SigningCredentials(key, SecurityAlgorithms.EcdsaSha256Signature);
118+
119+
// Use a custom CryptoProviderFactory so that keys are not cached and then disposed of, see below:
120+
// https://github.com/AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet/issues/1302
121+
return new SigningCredentials(key, SecurityAlgorithms.EcdsaSha256Signature)
122+
{
123+
CryptoProviderFactory = CryptoProviderFactory,
124+
};
114125
}
115126
}
116127
}

0 commit comments

Comments
 (0)