Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
969f48c
Update to ASP.NET Core 8 preview 3
martincostello Apr 16, 2023
be51cdf
Merge branch 'dev' into dev-v8
martincostello May 16, 2023
b3634b8
Remove TODO
martincostello May 16, 2023
f75002c
Update to ASP.NET Core 8 preview 4
martincostello May 16, 2023
40bfea3
Update to ASP.NET Core 8 preview 5
martincostello Jun 14, 2023
e389e7d
Update exception types (#784)
martincostello Jun 15, 2023
c7eb754
Merge branch 'dev' into dev-v8
martincostello Jun 19, 2023
4cd4ee7
Update to ASP.NET Core 8 preview 6
martincostello Jul 11, 2023
61e4165
Merge branch 'dev' into dev-v8
martincostello Aug 7, 2023
1a20061
Update to ASP.NET Core 8 preview 7
martincostello Aug 8, 2023
d86e1d5
Merge branch 'dev' into dev-v8
martincostello Aug 15, 2023
8b25479
Fix JumpCloud for .NET 8
martincostello Aug 15, 2023
872582c
Merge branch 'dev' into dev-v8
martincostello Aug 17, 2023
d9b218d
Update to ASP.NET Core 8 RC 1 (#801)
martincostello Sep 12, 2023
54962db
Remove obsolete members
martincostello Oct 1, 2023
3246aad
Use C# 12 features (#806)
martincostello Oct 2, 2023
5b940db
Use collection literals
martincostello Oct 2, 2023
837fa59
Update arcade (#805)
martincostello Oct 4, 2023
bdc6fbd
Update to ASP.NET Core 8 RC 2 (#810)
martincostello Oct 10, 2023
681afa0
Bump Microsoft.IdentityModel.Protocols.OpenIdConnect
martincostello Oct 17, 2023
492d96b
Bump JetBrains.Annotations
martincostello Nov 9, 2023
cedd813
AoT support
martincostello Nov 9, 2023
e46b08b
Fix flaky test
martincostello Nov 9, 2023
515ada5
Fix duplicated query parameters for VSO/AzDo (#814)
martincostello Nov 12, 2023
8dfccb3
Use unified BattleNet server (#813)
martincostello Nov 14, 2023
5b8528d
Update to .NET 8.0 RTM
martincostello Nov 14, 2023
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
Prev Previous commit
Next Next commit
Update to ASP.NET Core 8 preview 5
- Update to preview 5 of ASP.NET Core 8.
- Remove usage of `ISystemClock` and use `TimeProvider` instead.
- Suppress `CA1861` in tests.
- Apply some style suggestions from Visual Studio.
  • Loading branch information
martincostello committed Jun 14, 2023
commit 40bfea31595aee2563a5e7de0661adf54e7d556f
6 changes: 3 additions & 3 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
<PackageVersion Include="JetBrains.Annotations" Version="2022.1.0" />
<PackageVersion Include="JustEat.HttpClientInterception" Version="3.1.2" />
<PackageVersion Include="MartinCostello.Logging.XUnit" Version="0.3.0" />
<PackageVersion Include="Microsoft.AspNetCore.Authentication.Google" Version="8.0.0-preview.4.23260.4" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.0-preview.4.23260.4" />
<PackageVersion Include="Microsoft.AspNetCore.TestHost" Version="8.0.0-preview.4.23260.4" />
<PackageVersion Include="Microsoft.AspNetCore.Authentication.Google" Version="8.0.0-preview.5.23302.2" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.0-preview.5.23302.2" />
<PackageVersion Include="Microsoft.AspNetCore.TestHost" Version="8.0.0-preview.5.23302.2" />
<PackageVersion Include="Microsoft.IdentityModel.Protocols.OpenIdConnect" Version="6.16.0" />
<PackageVersion Include="Moq" Version="4.18.2" />
<PackageVersion Include="Shouldly" Version="4.1.0" />
Expand Down
2 changes: 1 addition & 1 deletion eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
-->
<PackageValidationBaselineVersion Condition="'$(PackageValidationBaselineVersion)' == ''">7.0.0</PackageValidationBaselineVersion>
<PreReleaseVersionLabel>preview</PreReleaseVersionLabel>
<PreReleaseVersionIteration>3</PreReleaseVersionIteration>
<PreReleaseVersionIteration>5</PreReleaseVersionIteration>
<PreReleaseBrandingLabel>Preview $(PreReleaseVersionIteration)</PreReleaseBrandingLabel>
<StabilizePackageVersion Condition="'$(StabilizePackageVersion)' == ''">false</StabilizePackageVersion>
<DotNetFinalVersionKind Condition="'$(StabilizePackageVersion)' == 'true'">release</DotNetFinalVersionKind>
Expand Down
4 changes: 2 additions & 2 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"sdk": {
"version": "8.0.100-preview.4.23260.5"
"version": "8.0.100-preview.5.23303.2"
},

"tools": {
"dotnet": "8.0.100-preview.4.23260.5"
"dotnet": "8.0.100-preview.5.23303.2"
},

"msbuild-sdks": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ public partial class AdobeIOAuthenticationHandler : OAuthHandler<AdobeIOAuthenti
public AdobeIOAuthenticationHandler(
[NotNull] IOptionsMonitor<AdobeIOAuthenticationOptions> options,
[NotNull] ILoggerFactory logger,
[NotNull] UrlEncoder encoder,
[NotNull] ISystemClock clock)
: base(options, logger, encoder, clock)
[NotNull] UrlEncoder encoder)
: base(options, logger, encoder)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ public partial class AlipayAuthenticationHandler : OAuthHandler<AlipayAuthentica
public AlipayAuthenticationHandler(
[NotNull] IOptionsMonitor<AlipayAuthenticationOptions> options,
[NotNull] ILoggerFactory logger,
[NotNull] UrlEncoder encoder,
[NotNull] ISystemClock clock)
: base(options, logger, encoder, clock)
[NotNull] UrlEncoder encoder)
: base(options, logger, encoder)
{
}

Expand Down Expand Up @@ -57,7 +56,7 @@ protected override async Task<OAuthTokenResponse> ExchangeCodeAsync([NotNull] OA
["grant_type"] = "authorization_code",
["method"] = "alipay.system.oauth.token",
["sign_type"] = "RSA2",
["timestamp"] = Clock.UtcNow.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture),
["timestamp"] = TimeProvider.GetUtcNow().ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture),
["version"] = "1.0",
};
tokenRequestParameters.Add("sign", GetRSA2Signature(tokenRequestParameters));
Expand Down Expand Up @@ -105,7 +104,7 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
["format"] = "JSON",
["method"] = "alipay.user.info.share",
["sign_type"] = "RSA2",
["timestamp"] = Clock.UtcNow.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture),
["timestamp"] = TimeProvider.GetUtcNow().ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture),
["version"] = "1.0",
};
parameters.Add("sign", GetRSA2Signature(parameters));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,11 @@ public partial class AmazonAuthenticationHandler : OAuthHandler<AmazonAuthentica
/// <param name="options">The authentication options.</param>
/// <param name="logger">The logger to use.</param>
/// <param name="encoder">The URL encoder to use.</param>
/// <param name="clock">The system clock to use.</param>
public AmazonAuthenticationHandler(
[NotNull] IOptionsMonitor<AmazonAuthenticationOptions> options,
[NotNull] ILoggerFactory logger,
[NotNull] UrlEncoder encoder,
[NotNull] ISystemClock clock)
: base(options, logger, encoder, clock)
[NotNull] UrlEncoder encoder)
: base(options, logger, encoder)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@ public partial class AmoCrmAuthenticationHandler : OAuthHandler<AmoCrmAuthentica
/// <param name="options">The authentication options.</param>
/// <param name="logger">The logger to use.</param>
/// <param name="encoder">The URL encoder to use.</param>
/// <param name="clock">The system clock to use.</param>
public AmoCrmAuthenticationHandler(
[NotNull] IOptionsMonitor<AmoCrmAuthenticationOptions> options,
[NotNull] ILoggerFactory logger,
[NotNull] UrlEncoder encoder,
[NotNull] ISystemClock clock)
: base(options, logger, encoder, clock)
[NotNull] UrlEncoder encoder)
: base(options, logger, encoder)
{
}

Expand Down
18 changes: 8 additions & 10 deletions src/AspNet.Security.OAuth.Apple/AppleAuthenticationHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,11 @@ public partial class AppleAuthenticationHandler : OAuthHandler<AppleAuthenticati
/// <param name="options">The authentication options.</param>
/// <param name="logger">The logger to use.</param>
/// <param name="encoder">The URL encoder to use.</param>
/// <param name="clock">The system clock to use.</param>
public AppleAuthenticationHandler(
[NotNull] IOptionsMonitor<AppleAuthenticationOptions> options,
[NotNull] ILoggerFactory logger,
[NotNull] UrlEncoder encoder,
[NotNull] ISystemClock clock)
: base(options, logger, encoder, clock)
[NotNull] UrlEncoder encoder)
: base(options, logger, encoder)
{
}

Expand All @@ -52,7 +50,7 @@ protected override string BuildChallengeUrl(
[NotNull] AuthenticationProperties properties,
[NotNull] string redirectUri)
{
string challengeUrl = base.BuildChallengeUrl(properties, redirectUri);
var challengeUrl = base.BuildChallengeUrl(properties, redirectUri);

// Apple requires the response mode to be form_post when the email or name scopes are requested
return QueryHelpers.AddQueryString(challengeUrl, "response_mode", "form_post");
Expand All @@ -67,7 +65,7 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
[NotNull] AuthenticationProperties properties,
[NotNull] OAuthTokenResponse tokens)
{
string? idToken = tokens.Response!.RootElement.GetString("id_token");
var idToken = tokens.Response!.RootElement.GetString("id_token");

Log.CreatingTicket(Logger);

Expand Down Expand Up @@ -186,7 +184,7 @@ private async Task<HandleRequestResult> HandleRemoteAuthenticateAsync(

if (properties == null)
{
return HandleRequestResult.Fail("The oauth state was missing or invalid.");
return HandleRequestResult.Fail("The OAuth state was missing or invalid.");
}

// OAuth2 10.12 CSRF
Expand Down Expand Up @@ -302,11 +300,11 @@ private async Task<HandleRequestResult> HandleRemoteAuthenticateAsync(

if (!string.IsNullOrEmpty(tokens.ExpiresIn))
{
if (int.TryParse(tokens.ExpiresIn, NumberStyles.Integer, CultureInfo.InvariantCulture, out int value))
if (int.TryParse(tokens.ExpiresIn, NumberStyles.Integer, CultureInfo.InvariantCulture, out var value))
{
// https://www.w3.org/TR/xmlschema-2/#dateTime
// https://msdn.microsoft.com/en-us/library/az4se3k1(v=vs.110).aspx
var expiresAt = Clock.UtcNow + TimeSpan.FromSeconds(value);
var expiresAt = TimeProvider.GetUtcNow().AddSeconds(value);

authTokens.Add(new AuthenticationToken()
{
Expand All @@ -316,7 +314,7 @@ private async Task<HandleRequestResult> HandleRemoteAuthenticateAsync(
}
}

string? idToken = tokens.Response?.RootElement.GetString("id_token");
var idToken = tokens.Response?.RootElement.GetString("id_token");

if (!string.IsNullOrEmpty(idToken))
{
Expand Down
53 changes: 20 additions & 33 deletions src/AspNet.Security.OAuth.Apple/ApplePostConfigureOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,22 @@ namespace AspNet.Security.OAuth.Apple;
public class ApplePostConfigureOptions : IPostConfigureOptions<AppleAuthenticationOptions>
{
private readonly IMemoryCache _cache;
private readonly ISystemClock _clock;
private readonly TimeProvider _timeProvider;
private readonly ILoggerFactory _loggerFactory;

/// <summary>
/// Initializes a new instance of the <see cref="ApplePostConfigureOptions"/> class.
/// </summary>
/// <param name="cache">The <see cref="IMemoryCache"/> to use.</param>
/// <param name="clock">The <see cref="ISystemClock"/> to use.</param>
/// <param name="timeProvider">The <see cref="TimeProvider"/> to use.</param>
/// <param name="loggerFactory">The <see cref="ILoggerFactory"/> to use.</param>
public ApplePostConfigureOptions(
IMemoryCache cache,
ISystemClock clock,
TimeProvider timeProvider,
ILoggerFactory loggerFactory)
{
_cache = cache;
_clock = clock;
_timeProvider = timeProvider;
_loggerFactory = loggerFactory ?? NullLoggerFactory.Instance;
}

Expand All @@ -50,20 +50,14 @@ public void PostConfigure(
// https://github.com/AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet/issues/1302
var cryptoProviderFactory = new CryptoProviderFactory() { CacheSignatureProviders = false };

if (options.ClientSecretGenerator is null)
{
options.ClientSecretGenerator = new DefaultAppleClientSecretGenerator(
_cache,
_clock,
cryptoProviderFactory,
_loggerFactory.CreateLogger<DefaultAppleClientSecretGenerator>());
}
options.ClientSecretGenerator ??= new DefaultAppleClientSecretGenerator(
_cache,
_timeProvider,
cryptoProviderFactory,
_loggerFactory.CreateLogger<DefaultAppleClientSecretGenerator>());

if (options.TokenValidator is null)
{
options.TokenValidator = new DefaultAppleIdTokenValidator(
_loggerFactory.CreateLogger<DefaultAppleIdTokenValidator>());
}
options.TokenValidator ??= new DefaultAppleIdTokenValidator(
_loggerFactory.CreateLogger<DefaultAppleIdTokenValidator>());

if (options.ConfigurationManager is null)
{
Expand All @@ -73,7 +67,7 @@ public void PostConfigure(
}

// As seen in:
// github.com/dotnet/aspnetcore/blob/master/src/Security/Authentication/OpenIdConnect/src/OpenIdConnectPostConfigureOptions.cs#L71-L102
// https://github.com/dotnet/aspnetcore/blob/master/src/Security/Authentication/OpenIdConnect/src/OpenIdConnectPostConfigureOptions.cs#L71-L102
// need this now to successfully instantiate ConfigurationManager below.
if (options.Backchannel is null)
{
Expand All @@ -91,21 +85,14 @@ public void PostConfigure(
new HttpDocumentRetriever(options.Backchannel));
}

if (options.SecurityTokenHandler is null)
options.SecurityTokenHandler ??= new JsonWebTokenHandler();
options.TokenValidationParameters ??= new TokenValidationParameters()
{
options.SecurityTokenHandler = new JsonWebTokenHandler();
}

if (options.TokenValidationParameters is null)
{
options.TokenValidationParameters = new TokenValidationParameters()
{
CryptoProviderFactory = cryptoProviderFactory,
ValidateAudience = true,
ValidateIssuer = true,
ValidAudience = options.ClientId,
ValidIssuer = options.TokenAudience
};
}
CryptoProviderFactory = cryptoProviderFactory,
ValidateAudience = true,
ValidateIssuer = true,
ValidAudience = options.ClientId,
ValidIssuer = options.TokenAudience
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,32 @@ namespace AspNet.Security.OAuth.Apple.Internal;
internal sealed partial class DefaultAppleClientSecretGenerator : AppleClientSecretGenerator
{
private readonly IMemoryCache _cache;
private readonly ISystemClock _clock;
private readonly TimeProvider _timeProvider;
private readonly ILogger _logger;
private readonly CryptoProviderFactory _cryptoProviderFactory;

public DefaultAppleClientSecretGenerator(
[NotNull] IMemoryCache cache,
[NotNull] ISystemClock clock,
[NotNull] TimeProvider clock,
[NotNull] CryptoProviderFactory cryptoProviderFactory,
[NotNull] ILogger<DefaultAppleClientSecretGenerator> logger)
{
_cache = cache;
_clock = clock;
_timeProvider = clock;
_cryptoProviderFactory = cryptoProviderFactory;
_logger = logger;
}

/// <inheritdoc />
public override async Task<string> GenerateAsync([NotNull] AppleGenerateClientSecretContext context)
{
string key = CreateCacheKey(context.Options);
var key = CreateCacheKey(context.Options);

var clientSecret = await _cache.GetOrCreateAsync(key, async (entry) =>
{
try
{
(string clientSecret, DateTimeOffset expiresAt) = await GenerateNewSecretAsync(context);
entry.AbsoluteExpiration = expiresAt;
(var clientSecret, entry.AbsoluteExpiration) = await GenerateNewSecretAsync(context);
return clientSecret;
}
catch (Exception ex)
Expand Down Expand Up @@ -71,7 +70,7 @@ private static string CreateCacheKey(AppleAuthenticationOptions options)
private async Task<(string ClientSecret, DateTimeOffset ExpiresAt)> GenerateNewSecretAsync(
[NotNull] AppleGenerateClientSecretContext context)
{
var expiresAt = _clock.UtcNow.Add(context.Options.ClientSecretExpiresAfter).UtcDateTime;
var expiresAt = _timeProvider.GetUtcNow().Add(context.Options.ClientSecretExpiresAfter).UtcDateTime;
var subject = new Claim("sub", context.Options.ClientId);

Log.GeneratingNewClientSecret(_logger, subject.Value, expiresAt);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ public partial class ArcGISAuthenticationHandler : OAuthHandler<ArcGISAuthentica
public ArcGISAuthenticationHandler(
[NotNull] IOptionsMonitor<ArcGISAuthenticationOptions> options,
[NotNull] ILoggerFactory logger,
[NotNull] UrlEncoder encoder,
[NotNull] ISystemClock clock)
: base(options, logger, encoder, clock)
[NotNull] UrlEncoder encoder)
: base(options, logger, encoder)
{
}

Expand Down
5 changes: 2 additions & 3 deletions src/AspNet.Security.OAuth.Asana/AsanaAuthenticationHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ public partial class AsanaAuthenticationHandler : OAuthHandler<AsanaAuthenticati
public AsanaAuthenticationHandler(
[NotNull] IOptionsMonitor<AsanaAuthenticationOptions> options,
[NotNull] ILoggerFactory logger,
[NotNull] UrlEncoder encoder,
[NotNull] ISystemClock clock)
: base(options, logger, encoder, clock)
[NotNull] UrlEncoder encoder)
: base(options, logger, encoder)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ public partial class AutodeskAuthenticationHandler : OAuthHandler<AutodeskAuthen
public AutodeskAuthenticationHandler(
[NotNull] IOptionsMonitor<AutodeskAuthenticationOptions> options,
[NotNull] ILoggerFactory logger,
[NotNull] UrlEncoder encoder,
[NotNull] ISystemClock clock)
: base(options, logger, encoder, clock)
[NotNull] UrlEncoder encoder)
: base(options, logger, encoder)
{
}

Expand Down
5 changes: 2 additions & 3 deletions src/AspNet.Security.OAuth.Baidu/BaiduAuthenticationHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ public partial class BaiduAuthenticationHandler : OAuthHandler<BaiduAuthenticati
public BaiduAuthenticationHandler(
[NotNull] IOptionsMonitor<BaiduAuthenticationOptions> options,
[NotNull] ILoggerFactory logger,
[NotNull] UrlEncoder encoder,
[NotNull] ISystemClock clock)
: base(options, logger, encoder, clock)
[NotNull] UrlEncoder encoder)
: base(options, logger, encoder)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ public partial class BasecampAuthenticationHandler : OAuthHandler<BasecampAuthen
public BasecampAuthenticationHandler(
[NotNull] IOptionsMonitor<BasecampAuthenticationOptions> options,
[NotNull] ILoggerFactory logger,
[NotNull] UrlEncoder encoder,
[NotNull] ISystemClock clock)
: base(options, logger, encoder, clock)
[NotNull] UrlEncoder encoder)
: base(options, logger, encoder)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ public partial class BattleNetAuthenticationHandler : OAuthHandler<BattleNetAuth
public BattleNetAuthenticationHandler(
[NotNull] IOptionsMonitor<BattleNetAuthenticationOptions> options,
[NotNull] ILoggerFactory logger,
[NotNull] UrlEncoder encoder,
[NotNull] ISystemClock clock)
: base(options, logger, encoder, clock)
[NotNull] UrlEncoder encoder)
: base(options, logger, encoder)
{
}

Expand Down
Loading