diff --git a/Directory.Build.props b/Directory.Build.props
index 3323a0bcc..d42d2900e 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -78,7 +78,7 @@
-
+
@@ -98,7 +98,7 @@
-
+
diff --git a/samples/Mvc.Client/Controllers/AuthenticationController.cs b/samples/Mvc.Client/Controllers/AuthenticationController.cs
index 77d8db67c..b2602638f 100644
--- a/samples/Mvc.Client/Controllers/AuthenticationController.cs
+++ b/samples/Mvc.Client/Controllers/AuthenticationController.cs
@@ -19,7 +19,7 @@ public class AuthenticationController : Controller
public async Task SignIn([FromForm] string provider)
{
// Note: the "provider" parameter corresponds to the external
- // authentication provider choosen by the user agent.
+ // authentication provider chosen by the user agent.
if (string.IsNullOrWhiteSpace(provider))
{
return BadRequest();
diff --git a/samples/Mvc.Client/Startup.cs b/samples/Mvc.Client/Startup.cs
index ead835315..5408ec6a9 100644
--- a/samples/Mvc.Client/Startup.cs
+++ b/samples/Mvc.Client/Startup.cs
@@ -9,18 +9,8 @@
namespace Mvc.Client;
-public class Startup
+public class Startup(IConfiguration configuration, IHostEnvironment hostingEnvironment)
{
- public Startup(IConfiguration configuration, IHostEnvironment hostingEnvironment)
- {
- Configuration = configuration;
- HostingEnvironment = hostingEnvironment;
- }
-
- public IConfiguration Configuration { get; }
-
- private IHostEnvironment HostingEnvironment { get; }
-
public void ConfigureServices(IServiceCollection services)
{
services.AddRouting();
@@ -38,21 +28,21 @@ public void ConfigureServices(IServiceCollection services)
.AddGoogle(options =>
{
- options.ClientId = Configuration["Google:ClientId"] ?? string.Empty;
- options.ClientSecret = Configuration["Google:ClientSecret"] ?? string.Empty;
+ options.ClientId = configuration["Google:ClientId"] ?? string.Empty;
+ options.ClientSecret = configuration["Google:ClientSecret"] ?? string.Empty;
})
.AddTwitter(options =>
{
- options.ClientId = Configuration["Twitter:ClientId"] ?? string.Empty;
- options.ClientSecret = Configuration["Twitter:ClientSecret"] ?? string.Empty;
+ options.ClientId = configuration["Twitter:ClientId"] ?? string.Empty;
+ options.ClientSecret = configuration["Twitter:ClientSecret"] ?? string.Empty;
})
.AddGitHub(options =>
{
- options.ClientId = Configuration["GitHub:ClientId"] ?? string.Empty;
- options.ClientSecret = Configuration["GitHub:ClientSecret"] ?? string.Empty;
- options.EnterpriseDomain = Configuration["GitHub:EnterpriseDomain"] ?? string.Empty;
+ options.ClientId = configuration["GitHub:ClientId"] ?? string.Empty;
+ options.ClientSecret = configuration["GitHub:ClientSecret"] ?? string.Empty;
+ options.EnterpriseDomain = configuration["GitHub:EnterpriseDomain"] ?? string.Empty;
options.Scope.Add("user:email");
})
@@ -69,8 +59,8 @@ public void ConfigureServices(IServiceCollection services)
.AddDropbox(options =>
{
- options.ClientId = Configuration["Dropbox:ClientId"] ?? string.Empty;
- options.ClientSecret = Configuration["Dropbox:ClientSecret"] ?? string.Empty;
+ options.ClientId = configuration["Dropbox:ClientId"] ?? string.Empty;
+ options.ClientSecret = configuration["Dropbox:ClientSecret"] ?? string.Empty;
});
services.AddMvc();
@@ -78,7 +68,7 @@ public void ConfigureServices(IServiceCollection services)
public void Configure(IApplicationBuilder app)
{
- if (HostingEnvironment.IsDevelopment())
+ if (hostingEnvironment.IsDevelopment())
{
IdentityModelEventSource.ShowPII = true;
}
diff --git a/src/AspNet.Security.OAuth.AdobeIO/AdobeIOAuthenticationHandler.cs b/src/AspNet.Security.OAuth.AdobeIO/AdobeIOAuthenticationHandler.cs
index ecfa38fa1..6fe1c8775 100644
--- a/src/AspNet.Security.OAuth.AdobeIO/AdobeIOAuthenticationHandler.cs
+++ b/src/AspNet.Security.OAuth.AdobeIO/AdobeIOAuthenticationHandler.cs
@@ -29,7 +29,7 @@ protected override async Task CreateTicketAsync(
[NotNull] AuthenticationProperties properties,
[NotNull] OAuthTokenResponse tokens)
{
- string address = QueryHelpers.AddQueryString(Options.UserInformationEndpoint, "client_id", Options.ClientId);
+ var address = QueryHelpers.AddQueryString(Options.UserInformationEndpoint, "client_id", Options.ClientId);
using var request = new HttpRequestMessage(HttpMethod.Get, address);
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
diff --git a/src/AspNet.Security.OAuth.Amazon/AmazonAuthenticationHandler.cs b/src/AspNet.Security.OAuth.Amazon/AmazonAuthenticationHandler.cs
index 0ae459585..415219e28 100644
--- a/src/AspNet.Security.OAuth.Amazon/AmazonAuthenticationHandler.cs
+++ b/src/AspNet.Security.OAuth.Amazon/AmazonAuthenticationHandler.cs
@@ -39,7 +39,7 @@ protected override async Task CreateTicketAsync(
[NotNull] AuthenticationProperties properties,
[NotNull] OAuthTokenResponse tokens)
{
- string endpoint = Options.UserInformationEndpoint;
+ var endpoint = Options.UserInformationEndpoint;
if (Options.Fields.Count > 0)
{
diff --git a/src/AspNet.Security.OAuth.AmoCrm/AmoCrmAuthenticationHandler.cs b/src/AspNet.Security.OAuth.AmoCrm/AmoCrmAuthenticationHandler.cs
index 0a8d02cb6..61909555c 100644
--- a/src/AspNet.Security.OAuth.AmoCrm/AmoCrmAuthenticationHandler.cs
+++ b/src/AspNet.Security.OAuth.AmoCrm/AmoCrmAuthenticationHandler.cs
@@ -38,7 +38,7 @@ protected override async Task CreateTicketAsync(
[NotNull] AuthenticationProperties properties,
[NotNull] OAuthTokenResponse tokens)
{
- string endpoint = Options.UserInformationEndpoint;
+ var endpoint = Options.UserInformationEndpoint;
using var request = new HttpRequestMessage(HttpMethod.Get, endpoint);
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
diff --git a/src/AspNet.Security.OAuth.Apple/AppleAuthenticationEvents.cs b/src/AspNet.Security.OAuth.Apple/AppleAuthenticationEvents.cs
index f200eba29..50b3facb7 100644
--- a/src/AspNet.Security.OAuth.Apple/AppleAuthenticationEvents.cs
+++ b/src/AspNet.Security.OAuth.Apple/AppleAuthenticationEvents.cs
@@ -14,7 +14,7 @@ public class AppleAuthenticationEvents : OAuthEvents
///
/// Gets or sets the delegate that is invoked when the method is invoked.
///
- public Func OnGenerateClientSecret { get; set; } = async context =>
+ public Func OnGenerateClientSecret { get; set; } = static async context =>
{
context.Options.ClientSecret = await context.Options.ClientSecretGenerator.GenerateAsync(context);
};
@@ -22,7 +22,7 @@ public class AppleAuthenticationEvents : OAuthEvents
///
/// Gets or sets the delegate that is invoked when the method is invoked.
///
- public Func OnValidateIdToken { get; set; } = async context =>
+ public Func OnValidateIdToken { get; set; } = static async context =>
{
await context.Options.TokenValidator.ValidateAsync(context);
};
diff --git a/src/AspNet.Security.OAuth.Apple/AppleAuthenticationHandler.cs b/src/AspNet.Security.OAuth.Apple/AppleAuthenticationHandler.cs
index 3946881d3..fb26c159e 100644
--- a/src/AspNet.Security.OAuth.Apple/AppleAuthenticationHandler.cs
+++ b/src/AspNet.Security.OAuth.Apple/AppleAuthenticationHandler.cs
@@ -19,22 +19,14 @@ namespace AspNet.Security.OAuth.Apple;
///
/// Defines a handler for authentication using Apple.
///
-public partial class AppleAuthenticationHandler : OAuthHandler
+/// The authentication options.
+/// The logger to use.
+/// The URL encoder to use.
+public partial class AppleAuthenticationHandler(
+ [NotNull] IOptionsMonitor options,
+ [NotNull] ILoggerFactory logger,
+ [NotNull] UrlEncoder encoder) : OAuthHandler(options, logger, encoder)
{
- ///
- /// Initializes a new instance of the class.
- ///
- /// The authentication options.
- /// The logger to use.
- /// The URL encoder to use.
- public AppleAuthenticationHandler(
- [NotNull] IOptionsMonitor options,
- [NotNull] ILoggerFactory logger,
- [NotNull] UrlEncoder encoder)
- : base(options, logger, encoder)
- {
- }
-
///
/// The handler calls methods on the events which give the application control at certain points where processing is occurring.
/// If it is not provided a default instance is supplied which does nothing when the methods are called.
@@ -133,7 +125,7 @@ protected virtual IEnumerable ExtractClaimsFromToken([NotNull] string tok
var claims = new List(securityToken.Claims)
{
- new Claim(ClaimTypes.NameIdentifier, securityToken.Subject, ClaimValueTypes.String, ClaimsIssuer),
+ new(ClaimTypes.NameIdentifier, securityToken.Subject, ClaimValueTypes.String, ClaimsIssuer),
};
var emailClaim = claims.Find((p) => string.Equals(p.Type, "email", StringComparison.Ordinal));
@@ -283,19 +275,19 @@ private async Task HandleRemoteAuthenticateAsync(
if (Options.SaveTokens)
{
- var authTokens = new List()
- {
- new AuthenticationToken() { Name = "access_token", Value = tokens.AccessToken },
- };
+ List authTokens =
+ [
+ new() { Name = "access_token", Value = tokens.AccessToken },
+ ];
if (!string.IsNullOrEmpty(tokens.RefreshToken))
{
- authTokens.Add(new AuthenticationToken() { Name = "refresh_token", Value = tokens.RefreshToken });
+ authTokens.Add(new() { Name = "refresh_token", Value = tokens.RefreshToken });
}
if (!string.IsNullOrEmpty(tokens.TokenType))
{
- authTokens.Add(new AuthenticationToken() { Name = "token_type", Value = tokens.TokenType });
+ authTokens.Add(new() { Name = "token_type", Value = tokens.TokenType });
}
if (!string.IsNullOrEmpty(tokens.ExpiresIn))
@@ -306,7 +298,7 @@ private async Task HandleRemoteAuthenticateAsync(
// https://msdn.microsoft.com/en-us/library/az4se3k1(v=vs.110).aspx
var expiresAt = TimeProvider.GetUtcNow().AddSeconds(value);
- authTokens.Add(new AuthenticationToken()
+ authTokens.Add(new()
{
Name = "expires_at",
Value = expiresAt.ToString("o", CultureInfo.InvariantCulture),
@@ -318,7 +310,7 @@ private async Task HandleRemoteAuthenticateAsync(
if (!string.IsNullOrEmpty(idToken))
{
- authTokens.Add(new AuthenticationToken() { Name = "id_token", Value = idToken });
+ authTokens.Add(new() { Name = "id_token", Value = idToken });
}
properties.StoreTokens(authTokens);
diff --git a/src/AspNet.Security.OAuth.Apple/AppleEmailClaimAction.cs b/src/AspNet.Security.OAuth.Apple/AppleEmailClaimAction.cs
index 86bba117b..18e4c2b84 100644
--- a/src/AspNet.Security.OAuth.Apple/AppleEmailClaimAction.cs
+++ b/src/AspNet.Security.OAuth.Apple/AppleEmailClaimAction.cs
@@ -10,16 +10,8 @@
namespace AspNet.Security.OAuth.Apple;
-internal sealed class AppleEmailClaimAction : ClaimAction
+internal sealed class AppleEmailClaimAction(AppleAuthenticationOptions options) : ClaimAction(ClaimTypes.Email, ClaimValueTypes.String)
{
- private readonly AppleAuthenticationOptions _options;
-
- internal AppleEmailClaimAction(AppleAuthenticationOptions options)
- : base(ClaimTypes.Email, ClaimValueTypes.String)
- {
- _options = options;
- }
-
public override void Run(JsonElement userData, ClaimsIdentity identity, string issuer)
{
if (!identity.HasClaim((p) => string.Equals(p.Type, ClaimType, StringComparison.OrdinalIgnoreCase)))
@@ -28,7 +20,7 @@ public override void Run(JsonElement userData, ClaimsIdentity identity, string i
if (!string.IsNullOrEmpty(emailClaim?.Value))
{
- identity.AddClaim(new Claim(ClaimType, emailClaim.Value, ValueType, _options.ClaimsIssuer));
+ identity.AddClaim(new Claim(ClaimType, emailClaim.Value, ValueType, options.ClaimsIssuer));
}
}
}
diff --git a/src/AspNet.Security.OAuth.Apple/AppleGenerateClientSecretContext.cs b/src/AspNet.Security.OAuth.Apple/AppleGenerateClientSecretContext.cs
index ddaf0853b..1a95cfd12 100644
--- a/src/AspNet.Security.OAuth.Apple/AppleGenerateClientSecretContext.cs
+++ b/src/AspNet.Security.OAuth.Apple/AppleGenerateClientSecretContext.cs
@@ -11,16 +11,12 @@ namespace AspNet.Security.OAuth.Apple;
///
/// Contains information about the current request.
///
-public class AppleGenerateClientSecretContext : BaseContext
+/// The HTTP context.
+/// The authentication scheme.
+/// The authentication options associated with the scheme.
+public class AppleGenerateClientSecretContext(
+ HttpContext context,
+ AuthenticationScheme scheme,
+ AppleAuthenticationOptions options) : BaseContext(context, scheme, options)
{
- ///
- /// Creates a new instance of the class.
- ///
- /// The HTTP context.
- /// The authentication scheme.
- /// The authentication options associated with the scheme.
- public AppleGenerateClientSecretContext(HttpContext context, AuthenticationScheme scheme, AppleAuthenticationOptions options)
- : base(context, scheme, options)
- {
- }
}
diff --git a/src/AspNet.Security.OAuth.Apple/ApplePostConfigureOptions.cs b/src/AspNet.Security.OAuth.Apple/ApplePostConfigureOptions.cs
index 936bc1e1d..140d48f0b 100644
--- a/src/AspNet.Security.OAuth.Apple/ApplePostConfigureOptions.cs
+++ b/src/AspNet.Security.OAuth.Apple/ApplePostConfigureOptions.cs
@@ -19,27 +19,15 @@ namespace AspNet.Security.OAuth.Apple;
///
/// A class used to setup defaults for all .
///
-public class ApplePostConfigureOptions : IPostConfigureOptions
+/// The to use.
+/// The to use.
+/// The to use.
+public class ApplePostConfigureOptions(
+ IMemoryCache cache,
+ TimeProvider timeProvider,
+ ILoggerFactory loggerFactory) : IPostConfigureOptions
{
- private readonly IMemoryCache _cache;
- private readonly TimeProvider _timeProvider;
- private readonly ILoggerFactory _loggerFactory;
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// The to use.
- /// The to use.
- /// The to use.
- public ApplePostConfigureOptions(
- IMemoryCache cache,
- TimeProvider timeProvider,
- ILoggerFactory loggerFactory)
- {
- _cache = cache;
- _timeProvider = timeProvider;
- _loggerFactory = loggerFactory ?? NullLoggerFactory.Instance;
- }
+ private readonly ILoggerFactory _loggerFactory = loggerFactory ?? NullLoggerFactory.Instance;
///
public void PostConfigure(
@@ -51,8 +39,8 @@ public void PostConfigure(
var cryptoProviderFactory = new CryptoProviderFactory() { CacheSignatureProviders = false };
options.ClientSecretGenerator ??= new DefaultAppleClientSecretGenerator(
- _cache,
- _timeProvider,
+ cache,
+ timeProvider,
cryptoProviderFactory,
_loggerFactory.CreateLogger());
diff --git a/src/AspNet.Security.OAuth.Apple/AppleValidateIdTokenContext.cs b/src/AspNet.Security.OAuth.Apple/AppleValidateIdTokenContext.cs
index 321e82739..f0dbb2734 100644
--- a/src/AspNet.Security.OAuth.Apple/AppleValidateIdTokenContext.cs
+++ b/src/AspNet.Security.OAuth.Apple/AppleValidateIdTokenContext.cs
@@ -11,23 +11,18 @@ namespace AspNet.Security.OAuth.Apple;
///
/// Contains information about the ID token to validate.
///
-public class AppleValidateIdTokenContext : BaseContext
+/// The HTTP context.
+/// The authentication scheme.
+/// The authentication options associated with the scheme.
+/// The Apple ID token for the user to validate.
+public class AppleValidateIdTokenContext(
+ HttpContext context,
+ AuthenticationScheme scheme,
+ AppleAuthenticationOptions options,
+ string idToken) : BaseContext(context, scheme, options)
{
- ///
- /// Creates a new instance of the class.
- ///
- /// The HTTP context.
- /// The authentication scheme.
- /// The authentication options associated with the scheme.
- /// The Apple ID token for the user to validate.
- public AppleValidateIdTokenContext(HttpContext context, AuthenticationScheme scheme, AppleAuthenticationOptions options, string idToken)
- : base(context, scheme, options)
- {
- IdToken = idToken;
- }
-
///
/// Gets the Apple ID token.
///
- public string IdToken { get; }
+ public string IdToken { get; } = idToken;
}
diff --git a/src/AspNet.Security.OAuth.Apple/Internal/DefaultAppleClientSecretGenerator.cs b/src/AspNet.Security.OAuth.Apple/Internal/DefaultAppleClientSecretGenerator.cs
index 8c0a4a394..b6c756717 100644
--- a/src/AspNet.Security.OAuth.Apple/Internal/DefaultAppleClientSecretGenerator.cs
+++ b/src/AspNet.Security.OAuth.Apple/Internal/DefaultAppleClientSecretGenerator.cs
@@ -12,31 +12,18 @@
namespace AspNet.Security.OAuth.Apple.Internal;
-internal sealed partial class DefaultAppleClientSecretGenerator : AppleClientSecretGenerator
+internal sealed partial class DefaultAppleClientSecretGenerator(
+ [NotNull] IMemoryCache cache,
+ [NotNull] TimeProvider timeProvider,
+ [NotNull] CryptoProviderFactory cryptoProviderFactory,
+ [NotNull] ILogger logger) : AppleClientSecretGenerator
{
- private readonly IMemoryCache _cache;
- private readonly TimeProvider _timeProvider;
- private readonly ILogger _logger;
- private readonly CryptoProviderFactory _cryptoProviderFactory;
-
- public DefaultAppleClientSecretGenerator(
- [NotNull] IMemoryCache cache,
- [NotNull] TimeProvider clock,
- [NotNull] CryptoProviderFactory cryptoProviderFactory,
- [NotNull] ILogger logger)
- {
- _cache = cache;
- _timeProvider = clock;
- _cryptoProviderFactory = cryptoProviderFactory;
- _logger = logger;
- }
-
///
public override async Task GenerateAsync([NotNull] AppleGenerateClientSecretContext context)
{
var key = CreateCacheKey(context.Options);
- var clientSecret = await _cache.GetOrCreateAsync(key, async (entry) =>
+ var clientSecret = await cache.GetOrCreateAsync(key, async (entry) =>
{
try
{
@@ -45,7 +32,7 @@ public override async Task GenerateAsync([NotNull] AppleGenerateClientSe
}
catch (Exception ex)
{
- Log.ClientSecretGenerationFailed(_logger, ex, context.Scheme.Name);
+ Log.ClientSecretGenerationFailed(logger, ex, context.Scheme.Name);
throw;
}
});
@@ -70,10 +57,10 @@ private static string CreateCacheKey(AppleAuthenticationOptions options)
private async Task<(string ClientSecret, DateTimeOffset ExpiresAt)> GenerateNewSecretAsync(
[NotNull] AppleGenerateClientSecretContext context)
{
- var expiresAt = _timeProvider.GetUtcNow().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);
+ Log.GeneratingNewClientSecret(logger, subject.Value, expiresAt);
var tokenDescriptor = new SecurityTokenDescriptor()
{
@@ -93,7 +80,7 @@ private static string CreateCacheKey(AppleAuthenticationOptions options)
clientSecret = context.Options.SecurityTokenHandler.CreateToken(tokenDescriptor);
}
- Log.GeneratedNewClientSecret(_logger, clientSecret);
+ Log.GeneratedNewClientSecret(logger, clientSecret);
return (clientSecret, expiresAt);
}
@@ -122,7 +109,7 @@ private SigningCredentials CreateSigningCredentials(string keyId, ECDsa algorith
// https://github.com/AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet/issues/1302
return new SigningCredentials(key, SecurityAlgorithms.EcdsaSha256)
{
- CryptoProviderFactory = _cryptoProviderFactory,
+ CryptoProviderFactory = cryptoProviderFactory,
};
}
diff --git a/src/AspNet.Security.OAuth.Apple/Internal/DefaultAppleIdTokenValidator.cs b/src/AspNet.Security.OAuth.Apple/Internal/DefaultAppleIdTokenValidator.cs
index c4a79c641..179d3232a 100644
--- a/src/AspNet.Security.OAuth.Apple/Internal/DefaultAppleIdTokenValidator.cs
+++ b/src/AspNet.Security.OAuth.Apple/Internal/DefaultAppleIdTokenValidator.cs
@@ -10,16 +10,9 @@
namespace AspNet.Security.OAuth.Apple.Internal;
-internal sealed partial class DefaultAppleIdTokenValidator : AppleIdTokenValidator
+internal sealed partial class DefaultAppleIdTokenValidator(
+ [NotNull] ILogger logger) : AppleIdTokenValidator
{
- private readonly ILogger _logger;
-
- public DefaultAppleIdTokenValidator(
- [NotNull] ILogger logger)
- {
- _logger = logger;
- }
-
public override async Task ValidateAsync([NotNull] AppleValidateIdTokenContext context)
{
if (context.Options.SecurityTokenHandler is null)
@@ -58,8 +51,8 @@ public override async Task ValidateAsync([NotNull] AppleValidateIdTokenContext c
}
catch (Exception ex)
{
- Log.TokenValidationFailed(_logger, ex, validationParameters.ValidIssuer, validationParameters.ValidAudience);
- Log.TokenInvalid(_logger, ex, context.IdToken);
+ Log.TokenValidationFailed(logger, ex, validationParameters.ValidIssuer, validationParameters.ValidAudience);
+ Log.TokenInvalid(logger, ex, context.IdToken);
throw;
}
}
diff --git a/src/AspNet.Security.OAuth.Baidu/BaiduAuthenticationHandler.cs b/src/AspNet.Security.OAuth.Baidu/BaiduAuthenticationHandler.cs
index ba6801431..5ca95ef3f 100644
--- a/src/AspNet.Security.OAuth.Baidu/BaiduAuthenticationHandler.cs
+++ b/src/AspNet.Security.OAuth.Baidu/BaiduAuthenticationHandler.cs
@@ -29,7 +29,7 @@ protected override async Task CreateTicketAsync(
[NotNull] AuthenticationProperties properties,
[NotNull] OAuthTokenResponse tokens)
{
- string address = QueryHelpers.AddQueryString(Options.UserInformationEndpoint, "access_token", tokens.AccessToken!);
+ var address = QueryHelpers.AddQueryString(Options.UserInformationEndpoint, "access_token", tokens.AccessToken!);
using var request = new HttpRequestMessage(HttpMethod.Get, address);
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
diff --git a/src/AspNet.Security.OAuth.Baidu/BaiduAuthenticationOptions.cs b/src/AspNet.Security.OAuth.Baidu/BaiduAuthenticationOptions.cs
index 9ef9983af..5ba006d8e 100644
--- a/src/AspNet.Security.OAuth.Baidu/BaiduAuthenticationOptions.cs
+++ b/src/AspNet.Security.OAuth.Baidu/BaiduAuthenticationOptions.cs
@@ -29,7 +29,7 @@ public BaiduAuthenticationOptions()
ClaimActions.MapCustomJson(BaiduAuthenticationConstants.Claims.Portrait,
user =>
{
- string? portrait = user.GetString("portrait");
+ var portrait = user.GetString("portrait");
return string.IsNullOrWhiteSpace(portrait) ?
null :
$"https://tb.himg.baidu.com/sys/portrait/item/{WebUtility.UrlEncode(portrait)}";
diff --git a/src/AspNet.Security.OAuth.BattleNet/BattleNetAuthenticationHandler.cs b/src/AspNet.Security.OAuth.BattleNet/BattleNetAuthenticationHandler.cs
index 4e02ea60f..66293ac46 100644
--- a/src/AspNet.Security.OAuth.BattleNet/BattleNetAuthenticationHandler.cs
+++ b/src/AspNet.Security.OAuth.BattleNet/BattleNetAuthenticationHandler.cs
@@ -29,7 +29,7 @@ protected override async Task CreateTicketAsync(
[NotNull] AuthenticationProperties properties,
[NotNull] OAuthTokenResponse tokens)
{
- string address = QueryHelpers.AddQueryString(Options.UserInformationEndpoint, "access_token", tokens.AccessToken!);
+ var address = QueryHelpers.AddQueryString(Options.UserInformationEndpoint, "access_token", tokens.AccessToken!);
using var request = new HttpRequestMessage(HttpMethod.Get, address);
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
diff --git a/src/AspNet.Security.OAuth.Bitbucket/BitbucketAuthenticationHandler.cs b/src/AspNet.Security.OAuth.Bitbucket/BitbucketAuthenticationHandler.cs
index 5fda22315..4a1ec4d87 100644
--- a/src/AspNet.Security.OAuth.Bitbucket/BitbucketAuthenticationHandler.cs
+++ b/src/AspNet.Security.OAuth.Bitbucket/BitbucketAuthenticationHandler.cs
@@ -51,7 +51,7 @@ protected override async Task CreateTicketAsync(
!identity.HasClaim(claim => claim.Type == ClaimTypes.Email) &&
Options.Scope.Contains("email"))
{
- string? address = await GetEmailAsync(tokens);
+ var address = await GetEmailAsync(tokens);
if (!string.IsNullOrEmpty(address))
{
diff --git a/src/AspNet.Security.OAuth.Coinbase/CoinbaseAuthenticationExtensions.cs b/src/AspNet.Security.OAuth.Coinbase/CoinbaseAuthenticationExtensions.cs
index c167ab4c4..f38cf494c 100644
--- a/src/AspNet.Security.OAuth.Coinbase/CoinbaseAuthenticationExtensions.cs
+++ b/src/AspNet.Security.OAuth.Coinbase/CoinbaseAuthenticationExtensions.cs
@@ -4,10 +4,7 @@
* for more information concerning the license and the contributors participating to this project.
*/
-using System;
using AspNet.Security.OAuth.Coinbase;
-using JetBrains.Annotations;
-using Microsoft.AspNetCore.Authentication;
namespace Microsoft.Extensions.DependencyInjection;
diff --git a/src/AspNet.Security.OAuth.Deezer/DeezerAuthenticationConstants.cs b/src/AspNet.Security.OAuth.Deezer/DeezerAuthenticationConstants.cs
index eec8a7bbc..51997775d 100644
--- a/src/AspNet.Security.OAuth.Deezer/DeezerAuthenticationConstants.cs
+++ b/src/AspNet.Security.OAuth.Deezer/DeezerAuthenticationConstants.cs
@@ -36,9 +36,9 @@ public static class Claims
public static class Scopes
{
///
- /// Access users basic information
- /// Includes name, firstname, profile picture only.
- /// Default permission
+ /// Access users basic information.
+ /// Includes name, first name and profile picture only.
+ /// Default permission.
///
public const string Identity = "basic_access";
diff --git a/src/AspNet.Security.OAuth.DigitalOcean/DigitalOceanAuthenticationHandler.cs b/src/AspNet.Security.OAuth.DigitalOcean/DigitalOceanAuthenticationHandler.cs
index bdd4488fc..9b079eba4 100644
--- a/src/AspNet.Security.OAuth.DigitalOcean/DigitalOceanAuthenticationHandler.cs
+++ b/src/AspNet.Security.OAuth.DigitalOcean/DigitalOceanAuthenticationHandler.cs
@@ -4,7 +4,6 @@
* for more information concerning the license and the contributors participating to this project.
*/
-using System.Net;
using System.Net.Http.Headers;
using System.Security.Claims;
using System.Text.Encodings.Web;
diff --git a/src/AspNet.Security.OAuth.Discord/DiscordAuthenticationHandler.cs b/src/AspNet.Security.OAuth.Discord/DiscordAuthenticationHandler.cs
index d9fd12737..369106ff2 100644
--- a/src/AspNet.Security.OAuth.Discord/DiscordAuthenticationHandler.cs
+++ b/src/AspNet.Security.OAuth.Discord/DiscordAuthenticationHandler.cs
@@ -29,7 +29,7 @@ protected override string BuildChallengeUrl(
[NotNull] AuthenticationProperties properties,
[NotNull] string redirectUri)
{
- string challengeUrl = base.BuildChallengeUrl(properties, redirectUri);
+ var challengeUrl = base.BuildChallengeUrl(properties, redirectUri);
if (!string.IsNullOrEmpty(Options.Prompt))
{
diff --git a/src/AspNet.Security.OAuth.Dropbox/DropboxAuthenticationHandler.cs b/src/AspNet.Security.OAuth.Dropbox/DropboxAuthenticationHandler.cs
index 6cebf2380..c0df4fc32 100644
--- a/src/AspNet.Security.OAuth.Dropbox/DropboxAuthenticationHandler.cs
+++ b/src/AspNet.Security.OAuth.Dropbox/DropboxAuthenticationHandler.cs
@@ -29,7 +29,7 @@ protected override string BuildChallengeUrl(
[NotNull] AuthenticationProperties properties,
[NotNull] string redirectUri)
{
- string challengeUrl = base.BuildChallengeUrl(properties, redirectUri);
+ var challengeUrl = base.BuildChallengeUrl(properties, redirectUri);
if (!string.IsNullOrEmpty(Options.AccessType))
{
diff --git a/src/AspNet.Security.OAuth.EVEOnline/EVEOnlineAuthenticationHandler.cs b/src/AspNet.Security.OAuth.EVEOnline/EVEOnlineAuthenticationHandler.cs
index 89da20a99..c4f7a71f5 100644
--- a/src/AspNet.Security.OAuth.EVEOnline/EVEOnlineAuthenticationHandler.cs
+++ b/src/AspNet.Security.OAuth.EVEOnline/EVEOnlineAuthenticationHandler.cs
@@ -34,7 +34,7 @@ protected override async Task CreateTicketAsync(
[NotNull] AuthenticationProperties properties,
[NotNull] OAuthTokenResponse tokens)
{
- string? accessToken = tokens.AccessToken;
+ var accessToken = tokens.AccessToken;
if (string.IsNullOrWhiteSpace(accessToken))
{
@@ -72,11 +72,12 @@ protected virtual IEnumerable ExtractClaimsFromToken([NotNull] string tok
var nameClaim = ExtractClaim(securityToken, "name");
var expClaim = ExtractClaim(securityToken, "exp");
- var claims = new List(securityToken.Claims);
-
- claims.Add(new Claim(ClaimTypes.NameIdentifier, securityToken.Subject.Replace("CHARACTER:EVE:", string.Empty, StringComparison.OrdinalIgnoreCase), ClaimValueTypes.String, ClaimsIssuer));
- claims.Add(new Claim(ClaimTypes.Name, nameClaim.Value, ClaimValueTypes.String, ClaimsIssuer));
- claims.Add(new Claim(ClaimTypes.Expiration, UnixTimeStampToDateTime(expClaim.Value), ClaimValueTypes.DateTime, ClaimsIssuer));
+ var claims = new List(securityToken.Claims)
+ {
+ new(ClaimTypes.NameIdentifier, securityToken.Subject.Replace("CHARACTER:EVE:", string.Empty, StringComparison.OrdinalIgnoreCase), ClaimValueTypes.String, ClaimsIssuer),
+ new(ClaimTypes.Name, nameClaim.Value, ClaimValueTypes.String, ClaimsIssuer),
+ new(ClaimTypes.Expiration, UnixTimeStampToDateTime(expClaim.Value), ClaimValueTypes.DateTime, ClaimsIssuer)
+ };
var scopes = claims.Where(x => string.Equals(x.Type, "scp", StringComparison.OrdinalIgnoreCase)).ToList();
@@ -96,23 +97,17 @@ protected virtual IEnumerable ExtractClaimsFromToken([NotNull] string tok
private static Claim ExtractClaim([NotNull] JsonWebToken token, [NotNull] string claim)
{
var extractedClaim = token.Claims.FirstOrDefault(x => string.Equals(x.Type, claim, StringComparison.OrdinalIgnoreCase));
-
- if (extractedClaim == null)
- {
- throw new AuthenticationFailureException($"The claim '{claim}' is missing from the EVEOnline JWT.");
- }
-
- return extractedClaim;
+ return extractedClaim ?? throw new AuthenticationFailureException($"The claim '{claim}' is missing from the EVEOnline JWT.");
}
private static string UnixTimeStampToDateTime(string unixTimeStamp)
{
- if (!long.TryParse(unixTimeStamp, NumberStyles.Integer, CultureInfo.InvariantCulture, out long unixTime))
+ if (!long.TryParse(unixTimeStamp, NumberStyles.Integer, CultureInfo.InvariantCulture, out var seconds))
{
throw new AuthenticationFailureException($"The value {unixTimeStamp} of the 'exp' claim is not a valid 64-bit integer.");
}
- DateTimeOffset offset = DateTimeOffset.FromUnixTimeSeconds(unixTime);
+ DateTimeOffset offset = DateTimeOffset.FromUnixTimeSeconds(seconds);
return offset.ToString("o", CultureInfo.InvariantCulture);
}
diff --git a/src/AspNet.Security.OAuth.EVEOnline/EVEOnlinePostConfigureOptions.cs b/src/AspNet.Security.OAuth.EVEOnline/EVEOnlinePostConfigureOptions.cs
index 620d40580..cd970e36b 100644
--- a/src/AspNet.Security.OAuth.EVEOnline/EVEOnlinePostConfigureOptions.cs
+++ b/src/AspNet.Security.OAuth.EVEOnline/EVEOnlinePostConfigureOptions.cs
@@ -1,4 +1,4 @@
-/*
+/*
* Licensed under the Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
* See https://github.com/aspnet-contrib/AspNet.Security.OAuth.Providers
* for more information concerning the license and the contributors participating to this project.
@@ -19,9 +19,6 @@ public void PostConfigure(
string? name,
[NotNull] EVEOnlineAuthenticationOptions options)
{
- if (options.SecurityTokenHandler == null)
- {
- options.SecurityTokenHandler = new JsonWebTokenHandler();
- }
+ options.SecurityTokenHandler ??= new JsonWebTokenHandler();
}
}
diff --git a/src/AspNet.Security.OAuth.GitHub/GitHubAuthenticationHandler.cs b/src/AspNet.Security.OAuth.GitHub/GitHubAuthenticationHandler.cs
index 7357da4ae..92ec25341 100644
--- a/src/AspNet.Security.OAuth.GitHub/GitHubAuthenticationHandler.cs
+++ b/src/AspNet.Security.OAuth.GitHub/GitHubAuthenticationHandler.cs
@@ -51,7 +51,7 @@ protected override async Task CreateTicketAsync(
!identity.HasClaim(claim => claim.Type == ClaimTypes.Email) &&
Options.Scope.Contains("user:email"))
{
- string? address = await GetEmailAsync(tokens);
+ var address = await GetEmailAsync(tokens);
if (!string.IsNullOrEmpty(address))
{
diff --git a/src/AspNet.Security.OAuth.Gitee/GiteeAuthenticationHandler.cs b/src/AspNet.Security.OAuth.Gitee/GiteeAuthenticationHandler.cs
index 404fe4f96..ca6fd45fc 100644
--- a/src/AspNet.Security.OAuth.Gitee/GiteeAuthenticationHandler.cs
+++ b/src/AspNet.Security.OAuth.Gitee/GiteeAuthenticationHandler.cs
@@ -52,7 +52,7 @@ protected override async Task CreateTicketAsync(
!identity.HasClaim(claim => claim.Type == ClaimTypes.Email) &&
Options.Scope.Contains("emails"))
{
- string? address = await GetEmailAsync(tokens);
+ var address = await GetEmailAsync(tokens);
if (!string.IsNullOrEmpty(address))
{
diff --git a/src/AspNet.Security.OAuth.Instagram/InstagramAuthenticationExtensions.cs b/src/AspNet.Security.OAuth.Instagram/InstagramAuthenticationExtensions.cs
index f34c4d526..02e76009e 100644
--- a/src/AspNet.Security.OAuth.Instagram/InstagramAuthenticationExtensions.cs
+++ b/src/AspNet.Security.OAuth.Instagram/InstagramAuthenticationExtensions.cs
@@ -4,10 +4,7 @@
* for more information concerning the license and the contributors participating to this project.
*/
-using System;
using AspNet.Security.OAuth.Instagram;
-using JetBrains.Annotations;
-using Microsoft.AspNetCore.Authentication;
namespace Microsoft.Extensions.DependencyInjection;
diff --git a/src/AspNet.Security.OAuth.Instagram/InstagramAuthenticationHandler.cs b/src/AspNet.Security.OAuth.Instagram/InstagramAuthenticationHandler.cs
index f8681af8f..698945db7 100644
--- a/src/AspNet.Security.OAuth.Instagram/InstagramAuthenticationHandler.cs
+++ b/src/AspNet.Security.OAuth.Instagram/InstagramAuthenticationHandler.cs
@@ -29,7 +29,7 @@ protected override async Task CreateTicketAsync(
[NotNull] AuthenticationProperties properties,
[NotNull] OAuthTokenResponse tokens)
{
- string address = QueryHelpers.AddQueryString(Options.UserInformationEndpoint, "access_token", tokens.AccessToken!);
+ var address = QueryHelpers.AddQueryString(Options.UserInformationEndpoint, "access_token", tokens.AccessToken!);
if (Options.Fields.Count > 0)
{
diff --git a/src/AspNet.Security.OAuth.JumpCloud/JumpCloudAuthenticationHandler.cs b/src/AspNet.Security.OAuth.JumpCloud/JumpCloudAuthenticationHandler.cs
index 8c1b4e3ce..5c50ef424 100644
--- a/src/AspNet.Security.OAuth.JumpCloud/JumpCloudAuthenticationHandler.cs
+++ b/src/AspNet.Security.OAuth.JumpCloud/JumpCloudAuthenticationHandler.cs
@@ -38,7 +38,7 @@ protected override async Task CreateTicketAsync(
[NotNull] AuthenticationProperties properties,
[NotNull] OAuthTokenResponse tokens)
{
- string endpoint = Options.UserInformationEndpoint;
+ var endpoint = Options.UserInformationEndpoint;
using var request = new HttpRequestMessage(HttpMethod.Get, endpoint);
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
diff --git a/src/AspNet.Security.OAuth.KakaoTalk/KakaoTalkAuthenticationOptions.cs b/src/AspNet.Security.OAuth.KakaoTalk/KakaoTalkAuthenticationOptions.cs
index 4c81a148a..c63d532f1 100644
--- a/src/AspNet.Security.OAuth.KakaoTalk/KakaoTalkAuthenticationOptions.cs
+++ b/src/AspNet.Security.OAuth.KakaoTalk/KakaoTalkAuthenticationOptions.cs
@@ -28,7 +28,7 @@ public KakaoTalkAuthenticationOptions()
ClaimActions.MapCustomJson(ClaimTypes.Name, user =>
{
JsonElement property = user;
- bool hasProperty = property.TryGetProperty("kakao_account", out property)
+ var hasProperty = property.TryGetProperty("kakao_account", out property)
&& property.TryGetProperty("profile", out property)
&& property.TryGetProperty("nickname", out property)
&& property.ValueKind == JsonValueKind.String;
diff --git a/src/AspNet.Security.OAuth.Kloudless/KloudlessAuthenticationConstants.cs b/src/AspNet.Security.OAuth.Kloudless/KloudlessAuthenticationConstants.cs
index c5641ffd5..bf70095a9 100644
--- a/src/AspNet.Security.OAuth.Kloudless/KloudlessAuthenticationConstants.cs
+++ b/src/AspNet.Security.OAuth.Kloudless/KloudlessAuthenticationConstants.cs
@@ -38,7 +38,7 @@ public static class Claims
public static class Scopes
{
///
- /// Use all available services in kloudless
+ /// Use all available services in Kloudless.
/// Default scope
///
public const string Any = "any";
diff --git a/src/AspNet.Security.OAuth.Kook/KookAuthenticationDefaults.cs b/src/AspNet.Security.OAuth.Kook/KookAuthenticationDefaults.cs
index 245b39a95..b25d6234a 100644
--- a/src/AspNet.Security.OAuth.Kook/KookAuthenticationDefaults.cs
+++ b/src/AspNet.Security.OAuth.Kook/KookAuthenticationDefaults.cs
@@ -12,12 +12,12 @@ namespace AspNet.Security.OAuth.Kook;
public static class KookAuthenticationDefaults
{
///
- /// Default value for .
+ /// Default value for .
///
public const string AuthenticationScheme = "Kook";
///
- /// Default value for .
+ /// Default value for .
///
public static readonly string DisplayName = "Kook";
diff --git a/src/AspNet.Security.OAuth.LinkedIn/LinkedInAuthenticationHandler.cs b/src/AspNet.Security.OAuth.LinkedIn/LinkedInAuthenticationHandler.cs
index d4fd1e57c..e5072f03c 100644
--- a/src/AspNet.Security.OAuth.LinkedIn/LinkedInAuthenticationHandler.cs
+++ b/src/AspNet.Security.OAuth.LinkedIn/LinkedInAuthenticationHandler.cs
@@ -30,7 +30,7 @@ protected override async Task CreateTicketAsync(
[NotNull] AuthenticationProperties properties,
[NotNull] OAuthTokenResponse tokens)
{
- string requestUri = Options.UserInformationEndpoint;
+ var requestUri = Options.UserInformationEndpoint;
var fields = Options.Fields
.Where(f => !string.Equals(f, LinkedInAuthenticationConstants.EmailAddressField, StringComparison.OrdinalIgnoreCase))
.ToList();
@@ -61,7 +61,7 @@ protected override async Task CreateTicketAsync(
if (!string.IsNullOrEmpty(Options.EmailAddressEndpoint) &&
Options.Fields.Contains(LinkedInAuthenticationConstants.EmailAddressField))
{
- string? email = await GetEmailAsync(tokens);
+ var email = await GetEmailAsync(tokens);
if (!string.IsNullOrEmpty(email))
{
identity.AddClaim(new Claim(ClaimTypes.Email, email, ClaimValueTypes.String, Options.ClaimsIssuer));
diff --git a/src/AspNet.Security.OAuth.MailRu/MailRuAuthenticationHandler.cs b/src/AspNet.Security.OAuth.MailRu/MailRuAuthenticationHandler.cs
index 08875dcef..2bce00dec 100644
--- a/src/AspNet.Security.OAuth.MailRu/MailRuAuthenticationHandler.cs
+++ b/src/AspNet.Security.OAuth.MailRu/MailRuAuthenticationHandler.cs
@@ -29,7 +29,7 @@ protected override async Task CreateTicketAsync(
[NotNull] AuthenticationProperties properties,
[NotNull] OAuthTokenResponse tokens)
{
- string address = QueryHelpers.AddQueryString(Options.UserInformationEndpoint, "access_token", tokens.AccessToken!);
+ var address = QueryHelpers.AddQueryString(Options.UserInformationEndpoint, "access_token", tokens.AccessToken!);
using var request = new HttpRequestMessage(HttpMethod.Get, address);
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
diff --git a/src/AspNet.Security.OAuth.Mixcloud/MixcloudAuthenticationDefaults.cs b/src/AspNet.Security.OAuth.Mixcloud/MixcloudAuthenticationDefaults.cs
index ae2da5a1a..59a4d3dd3 100644
--- a/src/AspNet.Security.OAuth.Mixcloud/MixcloudAuthenticationDefaults.cs
+++ b/src/AspNet.Security.OAuth.Mixcloud/MixcloudAuthenticationDefaults.cs
@@ -12,12 +12,12 @@ namespace AspNet.Security.OAuth.Mixcloud;
public static class MixcloudAuthenticationDefaults
{
///
- /// Default value for .
+ /// Default value for .
///
public const string AuthenticationScheme = "Mixcloud";
///
- /// Default value for .
+ /// Default value for .
///
public static readonly string DisplayName = "Mixcloud";
diff --git a/src/AspNet.Security.OAuth.Myob/MyobAuthenticationHandler.cs b/src/AspNet.Security.OAuth.Myob/MyobAuthenticationHandler.cs
index 02524e763..0622334f6 100644
--- a/src/AspNet.Security.OAuth.Myob/MyobAuthenticationHandler.cs
+++ b/src/AspNet.Security.OAuth.Myob/MyobAuthenticationHandler.cs
@@ -11,16 +11,11 @@
namespace AspNet.Security.OAuth.Myob;
-public class MyobAuthenticationHandler : OAuthHandler
+public class MyobAuthenticationHandler(
+ [NotNull] IOptionsMonitor options,
+ [NotNull] ILoggerFactory logger,
+ [NotNull] UrlEncoder encoder) : OAuthHandler(options, logger, encoder)
{
- public MyobAuthenticationHandler(
- [NotNull] IOptionsMonitor options,
- [NotNull] ILoggerFactory logger,
- [NotNull] UrlEncoder encoder)
- : base(options, logger, encoder)
- {
- }
-
protected override async Task CreateTicketAsync(
[NotNull] ClaimsIdentity identity,
[NotNull] AuthenticationProperties properties,
diff --git a/src/AspNet.Security.OAuth.Naver/NaverAuthenticationOptions.cs b/src/AspNet.Security.OAuth.Naver/NaverAuthenticationOptions.cs
index 8dd31819e..d529e464b 100644
--- a/src/AspNet.Security.OAuth.Naver/NaverAuthenticationOptions.cs
+++ b/src/AspNet.Security.OAuth.Naver/NaverAuthenticationOptions.cs
@@ -5,7 +5,6 @@
*/
using System.Security.Claims;
-using System.Text.Json;
using static AspNet.Security.OAuth.Naver.NaverAuthenticationConstants;
namespace AspNet.Security.OAuth.Naver;
diff --git a/src/AspNet.Security.OAuth.Nextcloud/NextcloudAuthenticationHandler.cs b/src/AspNet.Security.OAuth.Nextcloud/NextcloudAuthenticationHandler.cs
index 00eaabf26..6909384f8 100644
--- a/src/AspNet.Security.OAuth.Nextcloud/NextcloudAuthenticationHandler.cs
+++ b/src/AspNet.Security.OAuth.Nextcloud/NextcloudAuthenticationHandler.cs
@@ -28,8 +28,8 @@ protected override async Task CreateTicketAsync(
[NotNull] AuthenticationProperties properties,
[NotNull] OAuthTokenResponse tokens)
{
- string userId = tokens.Response!.RootElement.GetString("user_id") ?? string.Empty;
- string userEndpoint = Options.UserInformationEndpoint.TrimEnd('/');
+ var userId = tokens.Response!.RootElement.GetString("user_id") ?? string.Empty;
+ var userEndpoint = Options.UserInformationEndpoint.TrimEnd('/');
userEndpoint += $"/{Uri.EscapeDataString(userId)}";
using var request = new HttpRequestMessage(HttpMethod.Get, userEndpoint);
diff --git a/src/AspNet.Security.OAuth.Notion/NotionAuthenticationHandler.cs b/src/AspNet.Security.OAuth.Notion/NotionAuthenticationHandler.cs
index 432883414..8803d6a04 100644
--- a/src/AspNet.Security.OAuth.Notion/NotionAuthenticationHandler.cs
+++ b/src/AspNet.Security.OAuth.Notion/NotionAuthenticationHandler.cs
@@ -14,16 +14,11 @@
namespace AspNet.Security.OAuth.Notion;
-public class NotionAuthenticationHandler : OAuthHandler
+public class NotionAuthenticationHandler(
+ [NotNull] IOptionsMonitor options,
+ [NotNull] ILoggerFactory logger,
+ [NotNull] UrlEncoder encoder) : OAuthHandler(options, logger, encoder)
{
- public NotionAuthenticationHandler(
- [NotNull] IOptionsMonitor options,
- [NotNull] ILoggerFactory logger,
- [NotNull] UrlEncoder encoder)
- : base(options, logger, encoder)
- {
- }
-
protected override async Task ExchangeCodeAsync([NotNull] OAuthCodeExchangeContext context)
{
var tokenRequestParameters = new Dictionary()
diff --git a/src/AspNet.Security.OAuth.Okta/OktaAuthenticationDefaults.cs b/src/AspNet.Security.OAuth.Okta/OktaAuthenticationDefaults.cs
index bb922a1e3..d6093d56a 100644
--- a/src/AspNet.Security.OAuth.Okta/OktaAuthenticationDefaults.cs
+++ b/src/AspNet.Security.OAuth.Okta/OktaAuthenticationDefaults.cs
@@ -68,5 +68,5 @@ public static class OktaAuthenticationDefaults
/// Default path to use for .
///
public static readonly string UserInformationEndpointPath = string.Format(CultureInfo.InvariantCulture, UserInformationEndpointPathFormat, DefaultAuthorizationServer);
-#pragma warning disable CA1863
+#pragma warning restore CA1863
}
diff --git a/src/AspNet.Security.OAuth.Okta/OktaAuthenticationHandler.cs b/src/AspNet.Security.OAuth.Okta/OktaAuthenticationHandler.cs
index db1a7ed3c..00a1916b9 100644
--- a/src/AspNet.Security.OAuth.Okta/OktaAuthenticationHandler.cs
+++ b/src/AspNet.Security.OAuth.Okta/OktaAuthenticationHandler.cs
@@ -38,7 +38,7 @@ protected override async Task CreateTicketAsync(
[NotNull] AuthenticationProperties properties,
[NotNull] OAuthTokenResponse tokens)
{
- string endpoint = Options.UserInformationEndpoint;
+ var endpoint = Options.UserInformationEndpoint;
using var request = new HttpRequestMessage(HttpMethod.Get, endpoint);
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
diff --git a/src/AspNet.Security.OAuth.Patreon/PatreonAuthenticationHandler.cs b/src/AspNet.Security.OAuth.Patreon/PatreonAuthenticationHandler.cs
index 53befd90b..165f4729c 100644
--- a/src/AspNet.Security.OAuth.Patreon/PatreonAuthenticationHandler.cs
+++ b/src/AspNet.Security.OAuth.Patreon/PatreonAuthenticationHandler.cs
@@ -29,7 +29,7 @@ protected override async Task CreateTicketAsync(
[NotNull] AuthenticationProperties properties,
[NotNull] OAuthTokenResponse tokens)
{
- string endpoint = Options.UserInformationEndpoint;
+ var endpoint = Options.UserInformationEndpoint;
if (Options.Fields.Count > 0)
{
diff --git a/src/AspNet.Security.OAuth.PingOne/PingOneAuthenticationHandler.cs b/src/AspNet.Security.OAuth.PingOne/PingOneAuthenticationHandler.cs
index 45b8d07c7..6e35db98d 100644
--- a/src/AspNet.Security.OAuth.PingOne/PingOneAuthenticationHandler.cs
+++ b/src/AspNet.Security.OAuth.PingOne/PingOneAuthenticationHandler.cs
@@ -38,7 +38,7 @@ protected override async Task CreateTicketAsync(
[NotNull] AuthenticationProperties properties,
[NotNull] OAuthTokenResponse tokens)
{
- string endpoint = Options.UserInformationEndpoint;
+ var endpoint = Options.UserInformationEndpoint;
using var request = new HttpRequestMessage(HttpMethod.Get, endpoint);
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
diff --git a/src/AspNet.Security.OAuth.QuickBooks/QuickBooksAuthenticationHandler.cs b/src/AspNet.Security.OAuth.QuickBooks/QuickBooksAuthenticationHandler.cs
index 58941bd77..45513a00f 100644
--- a/src/AspNet.Security.OAuth.QuickBooks/QuickBooksAuthenticationHandler.cs
+++ b/src/AspNet.Security.OAuth.QuickBooks/QuickBooksAuthenticationHandler.cs
@@ -29,7 +29,7 @@ protected override async Task CreateTicketAsync(
[NotNull] AuthenticationProperties properties,
[NotNull] OAuthTokenResponse tokens)
{
- string address = QueryHelpers.AddQueryString(Options.UserInformationEndpoint, "client_id", Options.ClientId);
+ var address = QueryHelpers.AddQueryString(Options.UserInformationEndpoint, "client_id", Options.ClientId);
using var request = new HttpRequestMessage(HttpMethod.Get, address);
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
diff --git a/src/AspNet.Security.OAuth.Shopify/ShopifyAuthenticationDefaults.cs b/src/AspNet.Security.OAuth.Shopify/ShopifyAuthenticationDefaults.cs
index c3011970b..a8bfd0d71 100644
--- a/src/AspNet.Security.OAuth.Shopify/ShopifyAuthenticationDefaults.cs
+++ b/src/AspNet.Security.OAuth.Shopify/ShopifyAuthenticationDefaults.cs
@@ -85,7 +85,7 @@ public static class ShopifyAuthenticationDefaults
public static readonly string ShopifyEligibleForPaymentsClaimType = "urn:shopify:eligible_for_payments";
///
- /// The timezone that that the shop is using.
+ /// The time zone that that the shop is using.
///
public static readonly string ShopifyTimezoneClaimType = "urn:shopify:timezone";
}
diff --git a/src/AspNet.Security.OAuth.Shopify/ShopifyAuthenticationProperties.cs b/src/AspNet.Security.OAuth.Shopify/ShopifyAuthenticationProperties.cs
index f36fc28be..93b92b22f 100644
--- a/src/AspNet.Security.OAuth.Shopify/ShopifyAuthenticationProperties.cs
+++ b/src/AspNet.Security.OAuth.Shopify/ShopifyAuthenticationProperties.cs
@@ -7,9 +7,9 @@
namespace AspNet.Security.OAuth.Shopify;
///
-/// Substitue for to enforce setting shop name
+/// Substitute for to enforce setting shop name
/// before Challenge and provide an override for . You
-/// can accomplish the same thing by setting the approriate values in .
+/// can accomplish the same thing by setting the appropriate values in .
///
public class ShopifyAuthenticationProperties : AuthenticationProperties
{
diff --git a/src/AspNet.Security.OAuth.Slack/SlackAuthenticationHandler.cs b/src/AspNet.Security.OAuth.Slack/SlackAuthenticationHandler.cs
index 25ecf2d55..9d98d655a 100644
--- a/src/AspNet.Security.OAuth.Slack/SlackAuthenticationHandler.cs
+++ b/src/AspNet.Security.OAuth.Slack/SlackAuthenticationHandler.cs
@@ -29,7 +29,7 @@ protected override async Task CreateTicketAsync(
[NotNull] AuthenticationProperties properties,
[NotNull] OAuthTokenResponse tokens)
{
- string address = QueryHelpers.AddQueryString(Options.UserInformationEndpoint, "token", tokens.AccessToken!);
+ var address = QueryHelpers.AddQueryString(Options.UserInformationEndpoint, "token", tokens.AccessToken!);
using var request = new HttpRequestMessage(HttpMethod.Get, address);
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
diff --git a/src/AspNet.Security.OAuth.Snapchat/SnapchatAuthenticationHandler.cs b/src/AspNet.Security.OAuth.Snapchat/SnapchatAuthenticationHandler.cs
index 4b1f5096d..c8dcbe10e 100644
--- a/src/AspNet.Security.OAuth.Snapchat/SnapchatAuthenticationHandler.cs
+++ b/src/AspNet.Security.OAuth.Snapchat/SnapchatAuthenticationHandler.cs
@@ -6,10 +6,8 @@
using System.Net.Http.Headers;
using System.Security.Claims;
-using System.Text;
using System.Text.Encodings.Web;
using System.Text.Json;
-using Microsoft.AspNetCore.WebUtilities;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
@@ -30,7 +28,7 @@ protected override async Task CreateTicketAsync(
[NotNull] AuthenticationProperties properties,
[NotNull] OAuthTokenResponse tokens)
{
- string endpoint = Options.UserInformationEndpoint;
+ var endpoint = Options.UserInformationEndpoint;
using var request = new HttpRequestMessage(HttpMethod.Get, endpoint);
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
diff --git a/src/AspNet.Security.OAuth.Snapchat/SnapchatAuthenticationOptions.cs b/src/AspNet.Security.OAuth.Snapchat/SnapchatAuthenticationOptions.cs
index 54499f25c..45f801d8f 100644
--- a/src/AspNet.Security.OAuth.Snapchat/SnapchatAuthenticationOptions.cs
+++ b/src/AspNet.Security.OAuth.Snapchat/SnapchatAuthenticationOptions.cs
@@ -5,8 +5,6 @@
*/
using System.Security.Claims;
-using Microsoft.AspNetCore.Authentication;
-using Microsoft.AspNetCore.Http;
using static AspNet.Security.OAuth.Snapchat.SnapchatAuthenticationConstants;
namespace AspNet.Security.OAuth.Snapchat;
diff --git a/src/AspNet.Security.OAuth.SoundCloud/SoundCloudAuthenticationHandler.cs b/src/AspNet.Security.OAuth.SoundCloud/SoundCloudAuthenticationHandler.cs
index 8c66a4dac..63ba254e6 100644
--- a/src/AspNet.Security.OAuth.SoundCloud/SoundCloudAuthenticationHandler.cs
+++ b/src/AspNet.Security.OAuth.SoundCloud/SoundCloudAuthenticationHandler.cs
@@ -29,7 +29,7 @@ protected override async Task CreateTicketAsync(
[NotNull] AuthenticationProperties properties,
[NotNull] OAuthTokenResponse tokens)
{
- string address = QueryHelpers.AddQueryString(Options.UserInformationEndpoint, "oauth_token", tokens.AccessToken!);
+ var address = QueryHelpers.AddQueryString(Options.UserInformationEndpoint, "oauth_token", tokens.AccessToken!);
using var request = new HttpRequestMessage(HttpMethod.Get, address);
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
diff --git a/src/AspNet.Security.OAuth.SuperOffice/SuperOfficeAuthenticationHandler.cs b/src/AspNet.Security.OAuth.SuperOffice/SuperOfficeAuthenticationHandler.cs
index f067e82d7..9db969bcf 100644
--- a/src/AspNet.Security.OAuth.SuperOffice/SuperOfficeAuthenticationHandler.cs
+++ b/src/AspNet.Security.OAuth.SuperOffice/SuperOfficeAuthenticationHandler.cs
@@ -35,7 +35,7 @@ protected override async Task CreateTicketAsync(
[NotNull] AuthenticationProperties properties,
[NotNull] OAuthTokenResponse tokens)
{
- (string tenantId, string webApiUrl) = await ProcessIdTokenAndGetContactIdentifierAsync(tokens, properties, identity);
+ (var tenantId, var webApiUrl) = await ProcessIdTokenAndGetContactIdentifierAsync(tokens, properties, identity);
if (string.IsNullOrEmpty(tenantId))
{
@@ -82,7 +82,7 @@ protected override async Task CreateTicketAsync(
[NotNull] AuthenticationProperties properties,
[NotNull] ClaimsIdentity identity)
{
- string? idToken = tokens.Response!.RootElement.GetString("id_token");
+ var idToken = tokens.Response!.RootElement.GetString("id_token");
if (Options.SaveTokens)
{
diff --git a/src/AspNet.Security.OAuth.SuperOffice/SuperOfficeAuthenticationOptions.cs b/src/AspNet.Security.OAuth.SuperOffice/SuperOfficeAuthenticationOptions.cs
index a3f7160de..0d0e885cd 100644
--- a/src/AspNet.Security.OAuth.SuperOffice/SuperOfficeAuthenticationOptions.cs
+++ b/src/AspNet.Security.OAuth.SuperOffice/SuperOfficeAuthenticationOptions.cs
@@ -146,7 +146,7 @@ private string GetEnvironment()
///
private void UpdateEndpoints()
{
- string env = GetEnvironment();
+ var env = GetEnvironment();
#pragma warning disable CA1863
AuthorizationEndpoint = string.Format(CultureInfo.InvariantCulture,
diff --git a/src/AspNet.Security.OAuth.SuperOffice/SuperOfficeAuthenticationPostConfigureOptions.cs b/src/AspNet.Security.OAuth.SuperOffice/SuperOfficeAuthenticationPostConfigureOptions.cs
index 5c6a7fad3..c55814304 100644
--- a/src/AspNet.Security.OAuth.SuperOffice/SuperOfficeAuthenticationPostConfigureOptions.cs
+++ b/src/AspNet.Security.OAuth.SuperOffice/SuperOfficeAuthenticationPostConfigureOptions.cs
@@ -30,7 +30,7 @@ public void PostConfigure(
// As seen in:
// 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 == null)
+ if (options.Backchannel is null)
{
#pragma warning disable CA2000 // Dispose objects before losing scope
options.Backchannel = new HttpClient(options.BackchannelHttpHandler ?? new HttpClientHandler());
@@ -40,7 +40,7 @@ public void PostConfigure(
options.Backchannel.MaxResponseContentBufferSize = 1024 * 1024 * 10; // 10 MB
}
- if (options.ConfigurationManager == null)
+ if (options.ConfigurationManager is null)
{
if (string.IsNullOrEmpty(options.MetadataAddress))
{
@@ -57,9 +57,6 @@ public void PostConfigure(
};
}
- if (options.SecurityTokenHandler == null)
- {
- options.SecurityTokenHandler = new JsonWebTokenHandler();
- }
+ options.SecurityTokenHandler ??= new JsonWebTokenHandler();
}
}
diff --git a/src/AspNet.Security.OAuth.SuperOffice/SuperOfficeFunctionalRightsClaimAction.cs b/src/AspNet.Security.OAuth.SuperOffice/SuperOfficeFunctionalRightsClaimAction.cs
index f71098d91..2a7c76e23 100644
--- a/src/AspNet.Security.OAuth.SuperOffice/SuperOfficeFunctionalRightsClaimAction.cs
+++ b/src/AspNet.Security.OAuth.SuperOffice/SuperOfficeFunctionalRightsClaimAction.cs
@@ -10,19 +10,11 @@
namespace AspNet.Security.OAuth.SuperOffice;
-internal sealed class SuperOfficeFunctionalRightsClaimAction : ClaimAction
+internal sealed class SuperOfficeFunctionalRightsClaimAction(SuperOfficeAuthenticationOptions options) : ClaimAction(ClaimTypes.Email, ClaimValueTypes.String)
{
- private readonly SuperOfficeAuthenticationOptions _options;
-
- internal SuperOfficeFunctionalRightsClaimAction(SuperOfficeAuthenticationOptions options)
- : base(ClaimTypes.Email, ClaimValueTypes.String)
- {
- _options = options;
- }
-
public override void Run(JsonElement userData, ClaimsIdentity identity, string issuer)
{
- if (!_options.IncludeFunctionalRightsAsClaims ||
+ if (!options.IncludeFunctionalRightsAsClaims ||
userData.ValueKind != JsonValueKind.Object)
{
return;
diff --git a/src/AspNet.Security.OAuth.Twitter/TwitterAuthenticationHandler.cs b/src/AspNet.Security.OAuth.Twitter/TwitterAuthenticationHandler.cs
index 6757e3be0..b4103847f 100644
--- a/src/AspNet.Security.OAuth.Twitter/TwitterAuthenticationHandler.cs
+++ b/src/AspNet.Security.OAuth.Twitter/TwitterAuthenticationHandler.cs
@@ -106,10 +106,10 @@ protected override async Task ExchangeCodeAsync([NotNull] OA
return response.IsSuccessStatusCode switch
{
true => OAuthTokenResponse.Success(JsonDocument.Parse(body)),
- false => PrepareFailedOAuthTokenReponse(response, body)
+ false => PrepareFailedOAuthTokenResponse(response, body)
};
- static OAuthTokenResponse PrepareFailedOAuthTokenReponse(HttpResponseMessage response, string body)
+ static OAuthTokenResponse PrepareFailedOAuthTokenResponse(HttpResponseMessage response, string body)
{
var exception = GetStandardErrorException(JsonDocument.Parse(body));
diff --git a/src/AspNet.Security.OAuth.Xero/XeroAuthenticationOptions.cs b/src/AspNet.Security.OAuth.Xero/XeroAuthenticationOptions.cs
index 91b26497e..a09ab57dc 100644
--- a/src/AspNet.Security.OAuth.Xero/XeroAuthenticationOptions.cs
+++ b/src/AspNet.Security.OAuth.Xero/XeroAuthenticationOptions.cs
@@ -45,7 +45,7 @@ public XeroAuthenticationOptions()
/// Gets or sets the parameters used to validate identity tokens.
///
/// Contains the types and definitions required for validating a token.
- public TokenValidationParameters TokenValidationParameters { get; set; } = new TokenValidationParameters();
+ public TokenValidationParameters TokenValidationParameters { get; set; } = new();
///
/// Gets or sets the configuration manager responsible for retrieving, caching, and refreshing the
diff --git a/src/AspNet.Security.OAuth.Xero/XeroAuthenticationPostConfigureOptions.cs b/src/AspNet.Security.OAuth.Xero/XeroAuthenticationPostConfigureOptions.cs
index 6f3942aea..125e6f81c 100644
--- a/src/AspNet.Security.OAuth.Xero/XeroAuthenticationPostConfigureOptions.cs
+++ b/src/AspNet.Security.OAuth.Xero/XeroAuthenticationPostConfigureOptions.cs
@@ -45,21 +45,15 @@ public void PostConfigure(
options.Backchannel.MaxResponseContentBufferSize = 1024 * 1024 * 10; // 10 MB
}
- if (options.ConfigurationManager == null)
+ options.ConfigurationManager ??= new ConfigurationManager(
+ options.MetadataAddress,
+ new OpenIdConnectConfigurationRetriever(),
+ new HttpDocumentRetriever(options.Backchannel))
{
- options.ConfigurationManager = new ConfigurationManager(
- options.MetadataAddress,
- new OpenIdConnectConfigurationRetriever(),
- new HttpDocumentRetriever(options.Backchannel))
- {
- AutomaticRefreshInterval = TimeSpan.FromDays(1),
- RefreshInterval = TimeSpan.FromSeconds(30)
- };
- }
+ AutomaticRefreshInterval = TimeSpan.FromDays(1),
+ RefreshInterval = TimeSpan.FromSeconds(30)
+ };
- if (options.SecurityTokenHandler == null)
- {
- options.SecurityTokenHandler = new JsonWebTokenHandler();
- }
+ options.SecurityTokenHandler ??= new JsonWebTokenHandler();
}
}
diff --git a/src/AspNet.Security.OAuth.Xumm/XummAuthenticationHandler.cs b/src/AspNet.Security.OAuth.Xumm/XummAuthenticationHandler.cs
index f7c315e60..404a33a75 100644
--- a/src/AspNet.Security.OAuth.Xumm/XummAuthenticationHandler.cs
+++ b/src/AspNet.Security.OAuth.Xumm/XummAuthenticationHandler.cs
@@ -8,7 +8,6 @@
using System.Security.Claims;
using System.Text.Encodings.Web;
using System.Text.Json;
-using Microsoft.AspNetCore.WebUtilities;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
diff --git a/src/AspNet.Security.OAuth.Zendesk/ZendeskPostConfigureOptions.cs b/src/AspNet.Security.OAuth.Zendesk/ZendeskPostConfigureOptions.cs
index 3b1fba198..6a5977319 100644
--- a/src/AspNet.Security.OAuth.Zendesk/ZendeskPostConfigureOptions.cs
+++ b/src/AspNet.Security.OAuth.Zendesk/ZendeskPostConfigureOptions.cs
@@ -21,7 +21,7 @@ public void PostConfigure(
{
if (string.IsNullOrWhiteSpace(options.Domain))
{
- throw new ArgumentException($"No Zendesk domain configured", nameof(options));
+ throw new ArgumentException("No Zendesk domain configured", nameof(options));
}
options.AuthorizationEndpoint = CreateUrl(options.Domain, AuthorizationEndpointPath);
diff --git a/test/AspNet.Security.OAuth.Providers.Tests/AdobeIO/AdobeIOTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/AdobeIO/AdobeIOTests.cs
index 9ddbd8559..8ad5f73cf 100644
--- a/test/AspNet.Security.OAuth.Providers.Tests/AdobeIO/AdobeIOTests.cs
+++ b/test/AspNet.Security.OAuth.Providers.Tests/AdobeIO/AdobeIOTests.cs
@@ -8,21 +8,13 @@
namespace AspNet.Security.OAuth.AdobeIO;
-public class AdobeIOTests : OAuthTests
+public class AdobeIOTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper)
{
- public AdobeIOTests(ITestOutputHelper outputHelper)
- {
- OutputHelper = outputHelper;
- }
-
public override string DefaultScheme => AdobeIOAuthenticationDefaults.AuthenticationScheme;
protected internal override void RegisterAuthentication(AuthenticationBuilder builder)
{
- builder.AddAdobeIO(options =>
- {
- ConfigureDefaults(builder, options);
- });
+ builder.AddAdobeIO(options => ConfigureDefaults(builder, options));
}
[Theory]
@@ -35,16 +27,7 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu
[InlineData("urn:adobeio:account_type", "ent")]
[InlineData("urn:adobeio:email_verified", "True")]
public async Task Can_Sign_In_Using_AdobeIO(string claimType, string claimValue)
- {
- // Arrange
- using var server = CreateTestServer();
-
- // Act
- var claims = await AuthenticateUserAsync(server);
-
- // Assert
- AssertClaim(claims, claimType, claimValue);
- }
+ => await AuthenticateUserAndAssertClaimValue(claimType, claimValue);
[Fact]
public async Task BuildChallengeUrl_Generates_Correct_Url()
diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Alipay/AlipayTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Alipay/AlipayTests.cs
index 7e7780c6f..d0c752bde 100644
--- a/test/AspNet.Security.OAuth.Providers.Tests/Alipay/AlipayTests.cs
+++ b/test/AspNet.Security.OAuth.Providers.Tests/Alipay/AlipayTests.cs
@@ -8,13 +8,8 @@
namespace AspNet.Security.OAuth.Alipay;
-public class AlipayTests : OAuthTests
+public class AlipayTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper)
{
- public AlipayTests(ITestOutputHelper outputHelper)
- {
- OutputHelper = outputHelper;
- }
-
public override string DefaultScheme => AlipayAuthenticationDefaults.AuthenticationScheme;
protected internal override void RegisterAuthentication(AuthenticationBuilder builder)
@@ -35,16 +30,7 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu
[InlineData("urn:alipay:nick_name", "my-nickname")]
[InlineData("urn:alipay:gender", "M")]
public async Task Can_Sign_In_Using_Alipay(string claimType, string claimValue)
- {
- // Arrange
- using var server = CreateTestServer();
-
- // Act
- var claims = await AuthenticateUserAsync(server);
-
- // Assert
- AssertClaim(claims, claimType, claimValue);
- }
+ => await AuthenticateUserAndAssertClaimValue(claimType, claimValue);
[Theory]
[InlineData(false)]
diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Amazon/AmazonTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Amazon/AmazonTests.cs
index 1d4b6dfd9..33e697fcd 100644
--- a/test/AspNet.Security.OAuth.Providers.Tests/Amazon/AmazonTests.cs
+++ b/test/AspNet.Security.OAuth.Providers.Tests/Amazon/AmazonTests.cs
@@ -6,13 +6,8 @@
namespace AspNet.Security.OAuth.Amazon;
-public class AmazonTests : OAuthTests
+public class AmazonTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper)
{
- public AmazonTests(ITestOutputHelper outputHelper)
- {
- OutputHelper = outputHelper;
- }
-
public override string DefaultScheme => AmazonAuthenticationDefaults.AuthenticationScheme;
protected internal override void RegisterAuthentication(AuthenticationBuilder builder)
@@ -30,14 +25,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu
[InlineData(ClaimTypes.Email, "john@john-smith.local")]
[InlineData(ClaimTypes.PostalCode, "90210")]
public async Task Can_Sign_In_Using_Amazon(string claimType, string claimValue)
- {
- // Arrange
- using var server = CreateTestServer();
-
- // Act
- var claims = await AuthenticateUserAsync(server);
-
- // Assert
- AssertClaim(claims, claimType, claimValue);
- }
+ => await AuthenticateUserAndAssertClaimValue(claimType, claimValue);
}
diff --git a/test/AspNet.Security.OAuth.Providers.Tests/AmoCrm/AmoCrmTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/AmoCrm/AmoCrmTests.cs
index 001d0aba8..dbb4b46c4 100644
--- a/test/AspNet.Security.OAuth.Providers.Tests/AmoCrm/AmoCrmTests.cs
+++ b/test/AspNet.Security.OAuth.Providers.Tests/AmoCrm/AmoCrmTests.cs
@@ -6,7 +6,7 @@
namespace AspNet.Security.OAuth.AmoCrm;
-public class AmoCrmTests : OAuthTests
+public class AmoCrmTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper)
{
public override string DefaultScheme => AmoCrmAuthenticationDefaults.AuthenticationScheme;
@@ -25,14 +25,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu
[InlineData(ClaimTypes.Surname, "Smith")]
[InlineData(ClaimTypes.Email, "john@john-smith.local")]
public async Task Can_Sign_In_Using_AmoCrm(string claimType, string claimValue)
- {
- // Arrange
- using var server = CreateTestServer();
-
- // Act
- var claims = await AuthenticateUserAsync(server);
-
- // Assert
- AssertClaim(claims, claimType, claimValue);
- }
+ => await AuthenticateUserAndAssertClaimValue(claimType, claimValue);
}
diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Apple/AppleTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Apple/AppleTests.cs
index 2e02a4251..b6ce0c853 100644
--- a/test/AspNet.Security.OAuth.Providers.Tests/Apple/AppleTests.cs
+++ b/test/AspNet.Security.OAuth.Providers.Tests/Apple/AppleTests.cs
@@ -14,15 +14,10 @@
namespace AspNet.Security.OAuth.Apple;
-public class AppleTests : OAuthTests
+public class AppleTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper)
{
private static readonly JsonSerializerOptions SerializerOptions = new() { WriteIndented = true };
- public AppleTests(ITestOutputHelper outputHelper)
- {
- OutputHelper = outputHelper;
- }
-
public override string DefaultScheme => AppleAuthenticationDefaults.AuthenticationScheme;
protected override HttpMethod RedirectMethod => HttpMethod.Post;
@@ -60,13 +55,7 @@ static void ConfigureServices(IServiceCollection services)
});
}
- using var server = CreateTestServer(ConfigureServices);
-
- // Act
- var claims = await AuthenticateUserAsync(server);
-
- // Assert
- AssertClaim(claims, claimType, claimValue);
+ await AuthenticateUserAndAssertClaimValue(claimType, claimValue, ConfigureServices);
}
[Theory]
@@ -93,13 +82,7 @@ static void ConfigureServices(IServiceCollection services)
});
}
- using var server = CreateTestServer(ConfigureServices);
-
- // Act
- var claims = await AuthenticateUserAsync(server);
-
- // Assert
- AssertClaim(claims, claimType, claimValue);
+ await AuthenticateUserAndAssertClaimValue(claimType, claimValue, ConfigureServices);
}
[Theory]
@@ -133,13 +116,7 @@ static void ConfigureServices(IServiceCollection services)
RedirectParameters.Clear(); // Simulate second sign in where user data is not returned
- using var server = CreateTestServer(ConfigureServices);
-
- // Act
- var claims = await AuthenticateUserAsync(server);
-
- // Assert
- AssertClaim(claims, claimType, claimValue);
+ await AuthenticateUserAndAssertClaimValue(claimType, claimValue, ConfigureServices);
}
[Theory]
@@ -156,13 +133,7 @@ static void ConfigureServices(IServiceCollection services)
});
}
- using var server = CreateTestServer(ConfigureServices);
-
- // Act
- var claims = await AuthenticateUserAsync(server);
-
- // Assert
- AssertClaim(claims, claimType, claimValue);
+ await AuthenticateUserAndAssertClaimValue(claimType, claimValue, ConfigureServices);
}
[Fact]
@@ -354,7 +325,7 @@ void ConfigureServices(IServiceCollection services)
using var server = CreateTestServer(ConfigureServices);
// Act
- var claims = await AuthenticateUserAsync(server);
+ await AuthenticateUserAsync(server);
// Assert
onGenerateClientSecretEventRaised.ShouldBeTrue();
@@ -413,7 +384,7 @@ void ConfigureServices(IServiceCollection services)
using var server = CreateTestServer(ConfigureServices);
// Act
- var claims = await AuthenticateUserAsync(server);
+ await AuthenticateUserAsync(server);
// Assert
onGenerateClientSecretEventRaised.ShouldBeTrue();
@@ -501,7 +472,7 @@ public void Regenerate_Test_Jwts()
iat,
sub,
atHash,
- new Claim(JwtRegisteredClaimNames.Email, "johnny.appleseed@apple.local"),
+ new(JwtRegisteredClaimNames.Email, "johnny.appleseed@apple.local"),
emailVerified,
authTime,
nonceSupported,
@@ -519,11 +490,11 @@ public void Regenerate_Test_Jwts()
iat,
sub,
atHash,
- new Claim(JwtRegisteredClaimNames.Email, "ussckefuz6@privaterelay.appleid.com"),
+ new(JwtRegisteredClaimNames.Email, "ussckefuz6@privaterelay.appleid.com"),
emailVerified,
authTime,
nonceSupported,
- new Claim("is_private_email", "true"),
+ new("is_private_email", "true"),
};
var privateEmailToken = new JwtSecurityToken(
@@ -540,13 +511,13 @@ public void Regenerate_Test_Jwts()
// Copy the values from the test output to bundles.json if you need to regenerate the JWTs to edit the claims
// For https://appleid.apple.com/auth/keys
- OutputHelper!.WriteLine($"RSA key: {serializedRsaPublicKey}");
+ OutputHelper?.WriteLine($"RSA key: {serializedRsaPublicKey}");
// For https://appleid.apple.com/auth/token
- OutputHelper!.WriteLine($"Public email JWT: {publicEmailIdToken}");
+ OutputHelper?.WriteLine($"Public email JWT: {publicEmailIdToken}");
// For https://appleid.apple.local/auth/token/email
- OutputHelper!.WriteLine($"Private email JWT: {privateEmailIdToken}");
+ OutputHelper?.WriteLine($"Private email JWT: {privateEmailIdToken}");
}
private sealed class CustomAppleAuthenticationEvents : AppleAuthenticationEvents
diff --git a/test/AspNet.Security.OAuth.Providers.Tests/ArcGIS/ArcGISTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/ArcGIS/ArcGISTests.cs
index 46a2579ef..21e85f42b 100644
--- a/test/AspNet.Security.OAuth.Providers.Tests/ArcGIS/ArcGISTests.cs
+++ b/test/AspNet.Security.OAuth.Providers.Tests/ArcGIS/ArcGISTests.cs
@@ -6,13 +6,8 @@
namespace AspNet.Security.OAuth.ArcGIS;
-public class ArcGISTests : OAuthTests
+public class ArcGISTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper)
{
- public ArcGISTests(ITestOutputHelper outputHelper)
- {
- OutputHelper = outputHelper;
- }
-
public override string DefaultScheme => ArcGISAuthenticationDefaults.AuthenticationScheme;
protected internal override void RegisterAuthentication(AuthenticationBuilder builder)
@@ -25,14 +20,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu
[InlineData(ClaimTypes.Name, "John Smith")]
[InlineData(ClaimTypes.Email, "john@john-smith.local")]
public async Task Can_Sign_In_Using_ArcGIS(string claimType, string claimValue)
- {
- // Arrange
- using var server = CreateTestServer();
-
- // Act
- var claims = await AuthenticateUserAsync(server);
-
- // Assert
- AssertClaim(claims, claimType, claimValue);
- }
+ => await AuthenticateUserAndAssertClaimValue(claimType, claimValue);
}
diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Asana/AsanaTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Asana/AsanaTests.cs
index 2626bb480..898141a7b 100644
--- a/test/AspNet.Security.OAuth.Providers.Tests/Asana/AsanaTests.cs
+++ b/test/AspNet.Security.OAuth.Providers.Tests/Asana/AsanaTests.cs
@@ -6,13 +6,8 @@
namespace AspNet.Security.OAuth.Asana;
-public class AsanaTests : OAuthTests
+public class AsanaTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper)
{
- public AsanaTests(ITestOutputHelper outputHelper)
- {
- OutputHelper = outputHelper;
- }
-
public override string DefaultScheme => AsanaAuthenticationDefaults.AuthenticationScheme;
protected internal override void RegisterAuthentication(AuthenticationBuilder builder)
@@ -25,14 +20,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu
[InlineData(ClaimTypes.Name, "John Smith")]
[InlineData(ClaimTypes.Email, "john@john-smith.local")]
public async Task Can_Sign_In_Using_Asana(string claimType, string claimValue)
- {
- // Arrange
- using var server = CreateTestServer();
-
- // Act
- var claims = await AuthenticateUserAsync(server);
-
- // Assert
- AssertClaim(claims, claimType, claimValue);
- }
+ => await AuthenticateUserAndAssertClaimValue(claimType, claimValue);
}
diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Autodesk/AutodeskTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Autodesk/AutodeskTests.cs
index 3c46a75ff..26c9c874e 100644
--- a/test/AspNet.Security.OAuth.Providers.Tests/Autodesk/AutodeskTests.cs
+++ b/test/AspNet.Security.OAuth.Providers.Tests/Autodesk/AutodeskTests.cs
@@ -6,13 +6,8 @@
namespace AspNet.Security.OAuth.Autodesk;
-public class AutodeskTests : OAuthTests
+public class AutodeskTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper)
{
- public AutodeskTests(ITestOutputHelper outputHelper)
- {
- OutputHelper = outputHelper;
- }
-
public override string DefaultScheme => AutodeskAuthenticationDefaults.AuthenticationScheme;
protected internal override void RegisterAuthentication(AuthenticationBuilder builder)
@@ -28,14 +23,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu
[InlineData(ClaimTypes.Surname, "Smith")]
[InlineData("urn:autodesk:emailverified", "True")]
public async Task Can_Sign_In_Using_Autodesk(string claimType, string claimValue)
- {
- // Arrange
- using var server = CreateTestServer();
-
- // Act
- var claims = await AuthenticateUserAsync(server);
-
- // Assert
- AssertClaim(claims, claimType, claimValue);
- }
+ => await AuthenticateUserAndAssertClaimValue(claimType, claimValue);
}
diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Baidu/BaiduTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Baidu/BaiduTests.cs
index b6280ea1a..32ee25bd1 100644
--- a/test/AspNet.Security.OAuth.Providers.Tests/Baidu/BaiduTests.cs
+++ b/test/AspNet.Security.OAuth.Providers.Tests/Baidu/BaiduTests.cs
@@ -6,21 +6,13 @@
namespace AspNet.Security.OAuth.Baidu;
-public class BaiduTests : OAuthTests
+public class BaiduTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper)
{
- public BaiduTests(ITestOutputHelper outputHelper)
- {
- OutputHelper = outputHelper;
- }
-
public override string DefaultScheme => BaiduAuthenticationDefaults.AuthenticationScheme;
protected internal override void RegisterAuthentication(AuthenticationBuilder builder)
{
- builder.AddBaidu(options =>
- {
- ConfigureDefaults(builder, options);
- });
+ builder.AddBaidu(options => ConfigureDefaults(builder, options));
}
[Theory]
@@ -28,14 +20,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu
[InlineData(ClaimTypes.Name, "my-name")]
[InlineData("urn:baidu:portrait", "https://tb.himg.baidu.com/sys/portrait/item/my-portrait")]
public async Task Can_Sign_In_Using_Baidu(string claimType, string claimValue)
- {
- // Arrange
- using var server = CreateTestServer();
-
- // Act
- var claims = await AuthenticateUserAsync(server);
-
- // Assert
- AssertClaim(claims, claimType, claimValue);
- }
+ => await AuthenticateUserAndAssertClaimValue(claimType, claimValue);
}
diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Basecamp/BasecampTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Basecamp/BasecampTests.cs
index a52f4dfa1..21ec0b385 100644
--- a/test/AspNet.Security.OAuth.Providers.Tests/Basecamp/BasecampTests.cs
+++ b/test/AspNet.Security.OAuth.Providers.Tests/Basecamp/BasecampTests.cs
@@ -6,13 +6,8 @@
namespace AspNet.Security.OAuth.Basecamp;
-public class BasecampTests : OAuthTests
+public class BasecampTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper)
{
- public BasecampTests(ITestOutputHelper outputHelper)
- {
- OutputHelper = outputHelper;
- }
-
public override string DefaultScheme => BasecampAuthenticationDefaults.AuthenticationScheme;
protected internal override void RegisterAuthentication(AuthenticationBuilder builder)
@@ -26,14 +21,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu
[InlineData(ClaimTypes.Surname, "Smith")]
[InlineData(ClaimTypes.Email, "john@john-smith.local")]
public async Task Can_Sign_In_Using_Basecamp(string claimType, string claimValue)
- {
- // Arrange
- using var server = CreateTestServer();
-
- // Act
- var claims = await AuthenticateUserAsync(server);
-
- // Assert
- AssertClaim(claims, claimType, claimValue);
- }
+ => await AuthenticateUserAndAssertClaimValue(claimType, claimValue);
}
diff --git a/test/AspNet.Security.OAuth.Providers.Tests/BattleNet/BattleNetTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/BattleNet/BattleNetTests.cs
index a2f5490b2..26c6fd0e0 100644
--- a/test/AspNet.Security.OAuth.Providers.Tests/BattleNet/BattleNetTests.cs
+++ b/test/AspNet.Security.OAuth.Providers.Tests/BattleNet/BattleNetTests.cs
@@ -6,13 +6,8 @@
namespace AspNet.Security.OAuth.BattleNet;
-public class BattleNetTests : OAuthTests
+public class BattleNetTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper)
{
- public BattleNetTests(ITestOutputHelper outputHelper)
- {
- OutputHelper = outputHelper;
- }
-
public override string DefaultScheme => BattleNetAuthenticationDefaults.AuthenticationScheme;
protected internal override void RegisterAuthentication(AuthenticationBuilder builder)
@@ -24,14 +19,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu
[InlineData(ClaimTypes.NameIdentifier, "my-id")]
[InlineData(ClaimTypes.Name, "John Smith")]
public async Task Can_Sign_In_Using_BattleNet(string claimType, string claimValue)
- {
- // Arrange
- using var server = CreateTestServer();
-
- // Act
- var claims = await AuthenticateUserAsync(server);
-
- // Assert
- AssertClaim(claims, claimType, claimValue);
- }
+ => await AuthenticateUserAndAssertClaimValue(claimType, claimValue);
}
diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Bitbucket/BitbucketTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Bitbucket/BitbucketTests.cs
index 6d812d3db..b0c0e2dfe 100644
--- a/test/AspNet.Security.OAuth.Providers.Tests/Bitbucket/BitbucketTests.cs
+++ b/test/AspNet.Security.OAuth.Providers.Tests/Bitbucket/BitbucketTests.cs
@@ -6,13 +6,8 @@
namespace AspNet.Security.OAuth.Bitbucket;
-public class BitbucketTests : OAuthTests
+public class BitbucketTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper)
{
- public BitbucketTests(ITestOutputHelper outputHelper)
- {
- OutputHelper = outputHelper;
- }
-
public override string DefaultScheme => BitbucketAuthenticationDefaults.AuthenticationScheme;
protected internal override void RegisterAuthentication(AuthenticationBuilder builder)
@@ -32,14 +27,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu
[InlineData("urn:bitbucket:name", "John Smith")]
[InlineData("urn:bitbucket:url", "https://bitbucket.org")]
public async Task Can_Sign_In_Using_Bitbucket(string claimType, string claimValue)
- {
- // Arrange
- using var server = CreateTestServer();
-
- // Act
- var claims = await AuthenticateUserAsync(server);
-
- // Assert
- AssertClaim(claims, claimType, claimValue);
- }
+ => await AuthenticateUserAndAssertClaimValue(claimType, claimValue);
}
diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Buffer/BufferTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Buffer/BufferTests.cs
index b1b89a914..64c3e9f28 100644
--- a/test/AspNet.Security.OAuth.Providers.Tests/Buffer/BufferTests.cs
+++ b/test/AspNet.Security.OAuth.Providers.Tests/Buffer/BufferTests.cs
@@ -6,13 +6,8 @@
namespace AspNet.Security.OAuth.Buffer;
-public class BufferTests : OAuthTests
+public class BufferTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper)
{
- public BufferTests(ITestOutputHelper outputHelper)
- {
- OutputHelper = outputHelper;
- }
-
public override string DefaultScheme => BufferAuthenticationDefaults.AuthenticationScheme;
protected internal override void RegisterAuthentication(AuthenticationBuilder builder)
@@ -23,14 +18,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu
[Theory]
[InlineData(ClaimTypes.NameIdentifier, "my-id")]
public async Task Can_Sign_In_Using_Buffer(string claimType, string claimValue)
- {
- // Arrange
- using var server = CreateTestServer();
-
- // Act
- var claims = await AuthenticateUserAsync(server);
-
- // Assert
- AssertClaim(claims, claimType, claimValue);
- }
+ => await AuthenticateUserAndAssertClaimValue(claimType, claimValue);
}
diff --git a/test/AspNet.Security.OAuth.Providers.Tests/CiscoSpark/CiscoSparkTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/CiscoSpark/CiscoSparkTests.cs
index 67abe1765..67501ab3f 100644
--- a/test/AspNet.Security.OAuth.Providers.Tests/CiscoSpark/CiscoSparkTests.cs
+++ b/test/AspNet.Security.OAuth.Providers.Tests/CiscoSpark/CiscoSparkTests.cs
@@ -6,13 +6,8 @@
namespace AspNet.Security.OAuth.CiscoSpark;
-public class CiscoSparkTests : OAuthTests
+public class CiscoSparkTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper)
{
- public CiscoSparkTests(ITestOutputHelper outputHelper)
- {
- OutputHelper = outputHelper;
- }
-
public override string DefaultScheme => CiscoSparkAuthenticationDefaults.AuthenticationScheme;
protected internal override void RegisterAuthentication(AuthenticationBuilder builder)
@@ -25,14 +20,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu
[InlineData(ClaimTypes.Name, "John Smith")]
[InlineData(ClaimTypes.Email, "john@john-smith.local")]
public async Task Can_Sign_In_Using_CiscoSpark(string claimType, string claimValue)
- {
- // Arrange
- using var server = CreateTestServer();
-
- // Act
- var claims = await AuthenticateUserAsync(server);
-
- // Assert
- AssertClaim(claims, claimType, claimValue);
- }
+ => await AuthenticateUserAndAssertClaimValue(claimType, claimValue);
}
diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Coinbase/CoinbaseTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Coinbase/CoinbaseTests.cs
index 4446f8c05..3b22361d9 100644
--- a/test/AspNet.Security.OAuth.Providers.Tests/Coinbase/CoinbaseTests.cs
+++ b/test/AspNet.Security.OAuth.Providers.Tests/Coinbase/CoinbaseTests.cs
@@ -6,13 +6,8 @@
namespace AspNet.Security.OAuth.Coinbase;
-public class CoinbaseTests : OAuthTests
+public class CoinbaseTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper)
{
- public CoinbaseTests(ITestOutputHelper outputHelper)
- {
- OutputHelper = outputHelper;
- }
-
public override string DefaultScheme => CoinbaseAuthenticationDefaults.AuthenticationScheme;
protected internal override void RegisterAuthentication(AuthenticationBuilder builder)
@@ -30,14 +25,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu
[InlineData("urn:coinbase:profile_url", "https://coinbase.com/jsmith")]
[InlineData("urn:coinbase:username", "jsmith")]
public async Task Can_Sign_In_Using_Coinbase(string claimType, string claimValue)
- {
- // Arrange
- using var server = CreateTestServer();
-
- // Act
- var claims = await AuthenticateUserAsync(server);
-
- // Assert
- AssertClaim(claims, claimType, claimValue);
- }
+ => await AuthenticateUserAndAssertClaimValue(claimType, claimValue);
}
diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Deezer/DeezerTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Deezer/DeezerTests.cs
index 2d0745c49..cec48f04e 100644
--- a/test/AspNet.Security.OAuth.Providers.Tests/Deezer/DeezerTests.cs
+++ b/test/AspNet.Security.OAuth.Providers.Tests/Deezer/DeezerTests.cs
@@ -8,13 +8,8 @@
namespace AspNet.Security.OAuth.Deezer;
-public class DeezerTests : OAuthTests
+public class DeezerTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper)
{
- public DeezerTests(ITestOutputHelper outputHelper)
- {
- OutputHelper = outputHelper;
- }
-
public override string DefaultScheme => DeezerAuthenticationDefaults.AuthenticationScheme;
protected internal override void RegisterAuthentication(AuthenticationBuilder builder)
@@ -46,16 +41,7 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu
[InlineData(DeezerAuthenticationConstants.Claims.Type, "Type")]
[InlineData(DeezerAuthenticationConstants.Claims.ExplicitContentLevel, "ExplicitContentLevel")]
public async Task Can_Sign_In_Using_Deezer(string claimType, string claimValue)
- {
- // Arrange
- using var server = CreateTestServer();
-
- // Act
- var claims = await AuthenticateUserAsync(server);
-
- // Assert
- AssertClaim(claims, claimType, claimValue);
- }
+ => await AuthenticateUserAndAssertClaimValue(claimType, claimValue);
[Theory]
[InlineData(false)]
diff --git a/test/AspNet.Security.OAuth.Providers.Tests/DeviantArt/DeviantArtTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/DeviantArt/DeviantArtTests.cs
index f0e2eedc8..488140977 100644
--- a/test/AspNet.Security.OAuth.Providers.Tests/DeviantArt/DeviantArtTests.cs
+++ b/test/AspNet.Security.OAuth.Providers.Tests/DeviantArt/DeviantArtTests.cs
@@ -6,13 +6,8 @@
namespace AspNet.Security.OAuth.DeviantArt;
-public class DeviantArtTests : OAuthTests
+public class DeviantArtTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper)
{
- public DeviantArtTests(ITestOutputHelper outputHelper)
- {
- OutputHelper = outputHelper;
- }
-
public override string DefaultScheme => DeviantArtAuthenticationDefaults.AuthenticationScheme;
protected internal override void RegisterAuthentication(AuthenticationBuilder builder)
@@ -25,14 +20,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu
[InlineData(ClaimTypes.Name, "John Smith")]
[InlineData("urn:deviantart:name", "John Smith")]
public async Task Can_Sign_In_Using_Deviant_Art(string claimType, string claimValue)
- {
- // Arrange
- using var server = CreateTestServer();
-
- // Act
- var claims = await AuthenticateUserAsync(server);
-
- // Assert
- AssertClaim(claims, claimType, claimValue);
- }
+ => await AuthenticateUserAndAssertClaimValue(claimType, claimValue);
}
diff --git a/test/AspNet.Security.OAuth.Providers.Tests/DigitalOcean/DigitalOceanTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/DigitalOcean/DigitalOceanTests.cs
index 37086ad0e..9aa3cd173 100644
--- a/test/AspNet.Security.OAuth.Providers.Tests/DigitalOcean/DigitalOceanTests.cs
+++ b/test/AspNet.Security.OAuth.Providers.Tests/DigitalOcean/DigitalOceanTests.cs
@@ -4,25 +4,15 @@
* for more information concerning the license and the contributors participating to this project.
*/
-using Microsoft.AspNetCore.WebUtilities;
-
namespace AspNet.Security.OAuth.DigitalOcean;
-public class DigitalOceanTests : OAuthTests
+public class DigitalOceanTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper)
{
- public DigitalOceanTests(ITestOutputHelper outputHelper)
- {
- OutputHelper = outputHelper;
- }
-
public override string DefaultScheme => DigitalOceanAuthenticationDefaults.AuthenticationScheme;
protected internal override void RegisterAuthentication(AuthenticationBuilder builder)
{
- builder.AddDigitalOcean(options =>
- {
- ConfigureDefaults(builder, options);
- });
+ builder.AddDigitalOcean(options => ConfigureDefaults(builder, options));
}
[Theory]
@@ -31,14 +21,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu
[InlineData(ClaimTypes.Email, "me@test.com")]
[InlineData(DigitalOceanAuthenticationConstants.Claims.EmailVerified, "true")]
public async Task Can_Sign_In_Using_DigitalOcean(string claimType, string claimValue)
- {
- // Arrange
- using var server = CreateTestServer();
-
- // Act
- var claims = await AuthenticateUserAsync(server);
-
- // Assert
- AssertClaim(claims, claimType, claimValue);
- }
+ => await AuthenticateUserAndAssertClaimValue(claimType, claimValue);
}
diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Discord/DiscordTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Discord/DiscordTests.cs
index 538e61807..79be61d1b 100644
--- a/test/AspNet.Security.OAuth.Providers.Tests/Discord/DiscordTests.cs
+++ b/test/AspNet.Security.OAuth.Providers.Tests/Discord/DiscordTests.cs
@@ -9,13 +9,8 @@
namespace AspNet.Security.OAuth.Discord;
-public class DiscordTests : OAuthTests
+public class DiscordTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper)
{
- public DiscordTests(ITestOutputHelper outputHelper)
- {
- OutputHelper = outputHelper;
- }
-
public override string DefaultScheme => DiscordAuthenticationDefaults.AuthenticationScheme;
protected internal override void RegisterAuthentication(AuthenticationBuilder builder)
@@ -30,16 +25,7 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu
[InlineData(Claims.Discriminator, "1234")]
[InlineData(Claims.AvatarHash, "dummy-avatar-hash")]
public async Task Can_Sign_In_Using_Discord(string claimType, string claimValue)
- {
- // Arrange
- using var server = CreateTestServer();
-
- // Act
- var claims = await AuthenticateUserAsync(server);
-
- // Assert
- AssertClaim(claims, claimType, claimValue);
- }
+ => await AuthenticateUserAndAssertClaimValue(claimType, claimValue);
[Fact]
public async Task Authorization_Endpoint_Uri_by_Default_Does_Not_Contain_Prompt()
diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Dropbox/DropboxTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Dropbox/DropboxTests.cs
index 012e2b9b0..226467ce5 100644
--- a/test/AspNet.Security.OAuth.Providers.Tests/Dropbox/DropboxTests.cs
+++ b/test/AspNet.Security.OAuth.Providers.Tests/Dropbox/DropboxTests.cs
@@ -8,13 +8,8 @@
namespace AspNet.Security.OAuth.Dropbox;
-public class DropboxTests : OAuthTests
+public class DropboxTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper)
{
- public DropboxTests(ITestOutputHelper outputHelper)
- {
- OutputHelper = outputHelper;
- }
-
public override string DefaultScheme => DropboxAuthenticationDefaults.AuthenticationScheme;
protected internal override void RegisterAuthentication(AuthenticationBuilder builder)
@@ -27,16 +22,7 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu
[InlineData(ClaimTypes.Name, "Franz Ferdinand (Personal)")]
[InlineData(ClaimTypes.Email, "franz@gmail.com")]
public async Task Can_Sign_In_Using_Dropbox(string claimType, string claimValue)
- {
- // Arrange
- using var server = CreateTestServer();
-
- // Act
- var claims = await AuthenticateUserAsync(server);
-
- // Assert
- AssertClaim(claims, claimType, claimValue);
- }
+ => await AuthenticateUserAndAssertClaimValue(claimType, claimValue);
[Theory]
[InlineData("offline")]
@@ -67,7 +53,7 @@ void ConfigureServices(IServiceCollection services)
using var server = CreateTestServer(ConfigureServices);
// Act
- var claims = await AuthenticateUserAsync(server);
+ await AuthenticateUserAsync(server);
// Assert
accessTypeIsSet.ShouldBeTrue();
@@ -98,7 +84,7 @@ void ConfigureServices(IServiceCollection services)
using var server = CreateTestServer(ConfigureServices);
// Act
- var claims = await AuthenticateUserAsync(server);
+ await AuthenticateUserAsync(server);
// Assert
refreshTokenIsPresent.ShouldBeTrue();
diff --git a/test/AspNet.Security.OAuth.Providers.Tests/EVEOnline/EVEOnlineTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/EVEOnline/EVEOnlineTests.cs
index 87afd22e2..37bc02e19 100644
--- a/test/AspNet.Security.OAuth.Providers.Tests/EVEOnline/EVEOnlineTests.cs
+++ b/test/AspNet.Security.OAuth.Providers.Tests/EVEOnline/EVEOnlineTests.cs
@@ -1,4 +1,4 @@
-/*
+/*
* Licensed under the Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
* See https://github.com/aspnet-contrib/AspNet.Security.OAuth.Providers
* for more information concerning the license and the contributors participating to this project.
@@ -6,13 +6,8 @@
namespace AspNet.Security.OAuth.EVEOnline;
-public class EVEOnlineTests : OAuthTests
+public class EVEOnlineTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper)
{
- public EVEOnlineTests(ITestOutputHelper outputHelper)
- {
- OutputHelper = outputHelper;
- }
-
public override string DefaultScheme => EVEOnlineAuthenticationDefaults.AuthenticationScheme;
protected internal override void RegisterAuthentication(AuthenticationBuilder builder)
@@ -26,14 +21,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu
[InlineData(ClaimTypes.Expiration, "2019-12-31T23:59:59+00:00")]
[InlineData("urn:eveonline:scopes", "my-scopes")]
public async Task Can_Sign_In_Using_EVE_Online(string claimType, string claimValue)
- {
- // Arrange
- using var server = CreateTestServer();
-
- // Act
- var claims = await AuthenticateUserAsync(server);
-
- // Assert
- AssertClaim(claims, claimType, claimValue);
- }
+ => await AuthenticateUserAndAssertClaimValue(claimType, claimValue);
}
diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Ebay/EbayTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Ebay/EbayTests.cs
index 33440a0a1..1ae42a2dc 100644
--- a/test/AspNet.Security.OAuth.Providers.Tests/Ebay/EbayTests.cs
+++ b/test/AspNet.Security.OAuth.Providers.Tests/Ebay/EbayTests.cs
@@ -8,13 +8,8 @@
namespace AspNet.Security.OAuth.Ebay;
-public class EbayTests : OAuthTests
+public class EbayTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper)
{
- public EbayTests(ITestOutputHelper outputHelper)
- {
- OutputHelper = outputHelper;
- }
-
public override string DefaultScheme => EbayAuthenticationDefaults.AuthenticationScheme;
protected internal override void RegisterAuthentication(AuthenticationBuilder builder)
@@ -30,16 +25,7 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu
[InlineData(ClaimTypes.NameIdentifier, "my-id")]
[InlineData(ClaimTypes.Name, "John Smith")]
public async Task Can_Sign_In_Using_Ebay(string claimType, string claimValue)
- {
- // Arrange
- using var server = CreateTestServer();
-
- // Act
- var claims = await AuthenticateUserAsync(server);
-
- // Assert
- AssertClaim(claims, claimType, claimValue);
- }
+ => await AuthenticateUserAndAssertClaimValue(claimType, claimValue);
[Theory]
[InlineData(false)]
diff --git a/test/AspNet.Security.OAuth.Providers.Tests/ExactOnline/ExactOnlineTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/ExactOnline/ExactOnlineTests.cs
index 06aff9582..2b1e10522 100755
--- a/test/AspNet.Security.OAuth.Providers.Tests/ExactOnline/ExactOnlineTests.cs
+++ b/test/AspNet.Security.OAuth.Providers.Tests/ExactOnline/ExactOnlineTests.cs
@@ -8,13 +8,8 @@
namespace AspNet.Security.OAuth.ExactOnline;
-public class ExactOnlineTests : OAuthTests
+public class ExactOnlineTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper)
{
- public ExactOnlineTests(ITestOutputHelper outputHelper)
- {
- OutputHelper = outputHelper;
- }
-
public override string DefaultScheme => ExactOnlineAuthenticationDefaults.AuthenticationScheme;
protected internal override void RegisterAuthentication(AuthenticationBuilder builder)
@@ -31,14 +26,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu
[InlineData(Claims.Division, "12345")]
[InlineData(Claims.Company, "Division Name")]
public async Task Can_Sign_In_Using_ExactOnline(string claimType, string claimValue)
- {
- // Arrange
- using var server = CreateTestServer();
-
- // Act
- var claims = await AuthenticateUserAsync(server);
-
- // Assert
- AssertClaim(claims, claimType, claimValue);
- }
+ => await AuthenticateUserAndAssertClaimValue(claimType, claimValue);
}
diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Feishu/FeishuTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Feishu/FeishuTests.cs
index b39115e7a..d045a4006 100644
--- a/test/AspNet.Security.OAuth.Providers.Tests/Feishu/FeishuTests.cs
+++ b/test/AspNet.Security.OAuth.Providers.Tests/Feishu/FeishuTests.cs
@@ -6,21 +6,13 @@
namespace AspNet.Security.OAuth.Feishu;
-public class FeishuTests : OAuthTests
+public class FeishuTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper)
{
- public FeishuTests(ITestOutputHelper outputHelper)
- {
- OutputHelper = outputHelper;
- }
-
public override string DefaultScheme => FeishuAuthenticationDefaults.AuthenticationScheme;
protected internal override void RegisterAuthentication(AuthenticationBuilder builder)
{
- builder.AddFeishu(options =>
- {
- ConfigureDefaults(builder, options);
- });
+ builder.AddFeishu(options => ConfigureDefaults(builder, options));
}
[Theory]
@@ -29,14 +21,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu
[InlineData(FeishuAuthenticationConstants.Claims.UnionId, "test-union-id")]
[InlineData(FeishuAuthenticationConstants.Claims.Avatar, "https://www.feishu.cn/avatar/icon_big")]
public async Task Can_Sign_In_Using_Feishu(string claimType, string claimValue)
- {
- // Arrange
- using var server = CreateTestServer();
-
- // Act
- var claims = await AuthenticateUserAsync(server);
-
- // Assert
- AssertClaim(claims, claimType, claimValue);
- }
+ => await AuthenticateUserAndAssertClaimValue(claimType, claimValue);
}
diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Fitbit/FitbitTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Fitbit/FitbitTests.cs
index 2a4abe92e..a161fe51a 100644
--- a/test/AspNet.Security.OAuth.Providers.Tests/Fitbit/FitbitTests.cs
+++ b/test/AspNet.Security.OAuth.Providers.Tests/Fitbit/FitbitTests.cs
@@ -6,13 +6,8 @@
namespace AspNet.Security.OAuth.Fitbit;
-public class FitbitTests : OAuthTests
+public class FitbitTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper)
{
- public FitbitTests(ITestOutputHelper outputHelper)
- {
- OutputHelper = outputHelper;
- }
-
public override string DefaultScheme => FitbitAuthenticationDefaults.AuthenticationScheme;
protected internal override void RegisterAuthentication(AuthenticationBuilder builder)
@@ -26,14 +21,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu
[InlineData("urn:fitbit:avatar", "https://fitbit.local/john-smith/avatar.png")]
[InlineData("urn:fitbit:avatar150", "https://fitbit.local/john-smith/avatar-150.png")]
public async Task Can_Sign_In_Using_Fitbit(string claimType, string claimValue)
- {
- // Arrange
- using var server = CreateTestServer();
-
- // Act
- var claims = await AuthenticateUserAsync(server);
-
- // Assert
- AssertClaim(claims, claimType, claimValue);
- }
+ => await AuthenticateUserAndAssertClaimValue(claimType, claimValue);
}
diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Foursquare/FoursquareTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Foursquare/FoursquareTests.cs
index 411378f0b..78bc4168a 100644
--- a/test/AspNet.Security.OAuth.Providers.Tests/Foursquare/FoursquareTests.cs
+++ b/test/AspNet.Security.OAuth.Providers.Tests/Foursquare/FoursquareTests.cs
@@ -6,13 +6,8 @@
namespace AspNet.Security.OAuth.Foursquare;
-public class FoursquareTests : OAuthTests
+public class FoursquareTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper)
{
- public FoursquareTests(ITestOutputHelper outputHelper)
- {
- OutputHelper = outputHelper;
- }
-
public override string DefaultScheme => FoursquareAuthenticationDefaults.AuthenticationScheme;
protected internal override void RegisterAuthentication(AuthenticationBuilder builder)
@@ -29,14 +24,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu
[InlineData(ClaimTypes.Gender, "Male")]
[InlineData(ClaimTypes.Uri, "https://foursquare.local/john-smith")]
public async Task Can_Sign_In_Using_Foursquare(string claimType, string claimValue)
- {
- // Arrange
- using var server = CreateTestServer();
-
- // Act
- var claims = await AuthenticateUserAsync(server);
-
- // Assert
- AssertClaim(claims, claimType, claimValue);
- }
+ => await AuthenticateUserAndAssertClaimValue(claimType, claimValue);
}
diff --git a/test/AspNet.Security.OAuth.Providers.Tests/GitHub/GitHubEnterpriseTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/GitHub/GitHubEnterpriseTests.cs
index ccac87217..650c7d093 100644
--- a/test/AspNet.Security.OAuth.Providers.Tests/GitHub/GitHubEnterpriseTests.cs
+++ b/test/AspNet.Security.OAuth.Providers.Tests/GitHub/GitHubEnterpriseTests.cs
@@ -6,13 +6,8 @@
namespace AspNet.Security.OAuth.GitHub;
-public class GitHubEnterpriseTests : OAuthTests
+public class GitHubEnterpriseTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper)
{
- public GitHubEnterpriseTests(ITestOutputHelper outputHelper)
- {
- OutputHelper = outputHelper;
- }
-
public override string DefaultScheme => GitHubAuthenticationDefaults.AuthenticationScheme;
protected override string BundleName => "GitHub";
@@ -34,14 +29,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu
[InlineData("urn:github:name", "monalisa octocat")]
[InlineData("urn:github:url", "https://api.github.enterprise.local/users/octocat")]
public async Task Can_Sign_In_Using_GitHub_Enterprise(string claimType, string claimValue)
- {
- // Arrange
- using var server = CreateTestServer();
-
- // Act
- var claims = await AuthenticateUserAsync(server);
-
- // Assert
- AssertClaim(claims, claimType, claimValue);
- }
+ => await AuthenticateUserAndAssertClaimValue(claimType, claimValue);
}
diff --git a/test/AspNet.Security.OAuth.Providers.Tests/GitHub/GitHubTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/GitHub/GitHubTests.cs
index 8fd479f91..da3001590 100644
--- a/test/AspNet.Security.OAuth.Providers.Tests/GitHub/GitHubTests.cs
+++ b/test/AspNet.Security.OAuth.Providers.Tests/GitHub/GitHubTests.cs
@@ -6,13 +6,8 @@
namespace AspNet.Security.OAuth.GitHub;
-public class GitHubTests : OAuthTests
+public class GitHubTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper)
{
- public GitHubTests(ITestOutputHelper outputHelper)
- {
- OutputHelper = outputHelper;
- }
-
public override string DefaultScheme => GitHubAuthenticationDefaults.AuthenticationScheme;
protected internal override void RegisterAuthentication(AuthenticationBuilder builder)
@@ -31,14 +26,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu
[InlineData("urn:github:name", "monalisa octocat")]
[InlineData("urn:github:url", "https://api.github.com/users/octocat")]
public async Task Can_Sign_In_Using_GitHub(string claimType, string claimValue)
- {
- // Arrange
- using var server = CreateTestServer();
-
- // Act
- var claims = await AuthenticateUserAsync(server);
-
- // Assert
- AssertClaim(claims, claimType, claimValue);
- }
+ => await AuthenticateUserAndAssertClaimValue(claimType, claimValue);
}
diff --git a/test/AspNet.Security.OAuth.Providers.Tests/GitLab/GitLabTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/GitLab/GitLabTests.cs
index c99112968..b1ffa208c 100644
--- a/test/AspNet.Security.OAuth.Providers.Tests/GitLab/GitLabTests.cs
+++ b/test/AspNet.Security.OAuth.Providers.Tests/GitLab/GitLabTests.cs
@@ -6,21 +6,13 @@
namespace AspNet.Security.OAuth.GitLab;
-public class GitLabTests : OAuthTests
+public class GitLabTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper)
{
- public GitLabTests(ITestOutputHelper outputHelper)
- {
- OutputHelper = outputHelper;
- }
-
public override string DefaultScheme => GitLabAuthenticationDefaults.AuthenticationScheme;
protected internal override void RegisterAuthentication(AuthenticationBuilder builder)
{
- builder.AddGitLab(options =>
- {
- ConfigureDefaults(builder, options);
- });
+ builder.AddGitLab(options => ConfigureDefaults(builder, options));
}
[Theory]
@@ -31,14 +23,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu
[InlineData(GitLabAuthenticationConstants.Claims.Url, "https://gitlab.com/testuser")]
[InlineData(GitLabAuthenticationConstants.Claims.Avatar, "https://assets.gitlab-static.net/uploads/-/system/user/avatar/1234567/avatar.png")]
public async Task Can_Sign_In_Using_GitHub(string claimType, string claimValue)
- {
- // Arrange
- using var server = CreateTestServer();
-
- // Act
- var claims = await AuthenticateUserAsync(server);
-
- // Assert
- AssertClaim(claims, claimType, claimValue);
- }
+ => await AuthenticateUserAndAssertClaimValue(claimType, claimValue);
}
diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Gitee/GiteeTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Gitee/GiteeTests.cs
index 7e81a659d..bfc7e2cf5 100644
--- a/test/AspNet.Security.OAuth.Providers.Tests/Gitee/GiteeTests.cs
+++ b/test/AspNet.Security.OAuth.Providers.Tests/Gitee/GiteeTests.cs
@@ -6,13 +6,8 @@
namespace AspNet.Security.OAuth.Gitee;
-public class GiteeTests : OAuthTests
+public class GiteeTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper)
{
- public GiteeTests(ITestOutputHelper outputHelper)
- {
- OutputHelper = outputHelper;
- }
-
public override string DefaultScheme => GiteeAuthenticationDefaults.AuthenticationScheme;
protected internal override void RegisterAuthentication(AuthenticationBuilder builder)
@@ -27,14 +22,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu
[InlineData("urn:gitee:name", "name")]
[InlineData("urn:gitee:url", "https://gitee.com/api/v5/users/loginname")]
public async Task Can_Sign_In_Using_Gitee(string claimType, string claimValue)
- {
- // Arrange
- using var server = CreateTestServer();
-
- // Act
- var claims = await AuthenticateUserAsync(server);
-
- // Assert
- AssertClaim(claims, claimType, claimValue);
- }
+ => await AuthenticateUserAndAssertClaimValue(claimType, claimValue);
}
diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Harvest/HarvestTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Harvest/HarvestTests.cs
index 346d809e8..9abe7b1c0 100644
--- a/test/AspNet.Security.OAuth.Providers.Tests/Harvest/HarvestTests.cs
+++ b/test/AspNet.Security.OAuth.Providers.Tests/Harvest/HarvestTests.cs
@@ -6,21 +6,13 @@
namespace AspNet.Security.OAuth.Harvest;
-public class HarvestTests : OAuthTests
+public class HarvestTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper)
{
- public HarvestTests(ITestOutputHelper outputHelper)
- {
- OutputHelper = outputHelper;
- }
-
public override string DefaultScheme => HarvestAuthenticationDefaults.AuthenticationScheme;
protected internal override void RegisterAuthentication(AuthenticationBuilder builder)
{
- builder.AddHarvest(options =>
- {
- ConfigureDefaults(builder, options);
- });
+ builder.AddHarvest(options => ConfigureDefaults(builder, options));
}
[Theory]
@@ -30,14 +22,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu
[InlineData(ClaimTypes.Surname, "Smith")]
[InlineData(ClaimTypes.Email, "john.smith@mail.com")]
public async Task Can_Sign_In_Using_Harvest(string claimType, string claimValue)
- {
- // Arrange
- using var server = CreateTestServer();
-
- // Act
- var claims = await AuthenticateUserAsync(server);
-
- // Assert
- AssertClaim(claims, claimType, claimValue);
- }
+ => await AuthenticateUserAndAssertClaimValue(claimType, claimValue);
}
diff --git a/test/AspNet.Security.OAuth.Providers.Tests/HealthGraph/HealthGraphTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/HealthGraph/HealthGraphTests.cs
index a746debef..775d4cc15 100644
--- a/test/AspNet.Security.OAuth.Providers.Tests/HealthGraph/HealthGraphTests.cs
+++ b/test/AspNet.Security.OAuth.Providers.Tests/HealthGraph/HealthGraphTests.cs
@@ -6,13 +6,8 @@
namespace AspNet.Security.OAuth.HealthGraph;
-public class HealthGraphTests : OAuthTests
+public class HealthGraphTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper)
{
- public HealthGraphTests(ITestOutputHelper outputHelper)
- {
- OutputHelper = outputHelper;
- }
-
public override string DefaultScheme => HealthGraphAuthenticationDefaults.AuthenticationScheme;
protected internal override void RegisterAuthentication(AuthenticationBuilder builder)
@@ -23,14 +18,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu
[Theory]
[InlineData(ClaimTypes.NameIdentifier, "my-id")]
public async Task Can_Sign_In_Using_HealthGraph(string claimType, string claimValue)
- {
- // Arrange
- using var server = CreateTestServer();
-
- // Act
- var claims = await AuthenticateUserAsync(server);
-
- // Assert
- AssertClaim(claims, claimType, claimValue);
- }
+ => await AuthenticateUserAndAssertClaimValue(claimType, claimValue);
}
diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Huawei/HuaweiTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Huawei/HuaweiTests.cs
index 513c55d64..1fe29ed58 100644
--- a/test/AspNet.Security.OAuth.Providers.Tests/Huawei/HuaweiTests.cs
+++ b/test/AspNet.Security.OAuth.Providers.Tests/Huawei/HuaweiTests.cs
@@ -6,13 +6,8 @@
namespace AspNet.Security.OAuth.Huawei;
-public class HuaweiTests : OAuthTests
+public class HuaweiTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper)
{
- public HuaweiTests(ITestOutputHelper outputHelper)
- {
- OutputHelper = outputHelper;
- }
-
public override string DefaultScheme => HuaweiAuthenticationDefaults.AuthenticationScheme;
protected internal override void RegisterAuthentication(AuthenticationBuilder builder)
@@ -34,14 +29,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu
[InlineData(HuaweiAuthenticationConstants.Claims.Avatar, "test-head-picture-url.jpg")]
[InlineData(ClaimTypes.Email, "test-email@test")]
public async Task Can_Sign_In_Using_Huawei(string claimType, string claimValue)
- {
- // Arrange
- using var server = CreateTestServer();
-
- // Act
- var claims = await AuthenticateUserAsync(server);
-
- // Assert
- AssertClaim(claims, claimType, claimValue);
- }
+ => await AuthenticateUserAndAssertClaimValue(claimType, claimValue);
}
diff --git a/test/AspNet.Security.OAuth.Providers.Tests/HubSpot/HubSpotTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/HubSpot/HubSpotTests.cs
index 9245bcdf2..efaa9b98d 100644
--- a/test/AspNet.Security.OAuth.Providers.Tests/HubSpot/HubSpotTests.cs
+++ b/test/AspNet.Security.OAuth.Providers.Tests/HubSpot/HubSpotTests.cs
@@ -6,13 +6,8 @@
namespace AspNet.Security.OAuth.HubSpot;
-public class HubSpotTests : OAuthTests
+public class HubSpotTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper)
{
- public HubSpotTests(ITestOutputHelper outputHelper)
- {
- OutputHelper = outputHelper;
- }
-
public override string DefaultScheme => HubSpotAuthenticationDefaults.AuthenticationScheme;
protected internal override void RegisterAuthentication(AuthenticationBuilder builder)
@@ -28,14 +23,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu
[InlineData("urn:HubSpot:app_id", "696969")]
[InlineData("urn:HubSpot:hub_domain", "dev-13371337.com")]
public async Task Can_Sign_In_Using_HubSpot(string claimType, string claimValue)
- {
- // Arrange
- using var server = CreateTestServer();
-
- // Act
- var claims = await AuthenticateUserAsync(server);
-
- // Assert
- AssertClaim(claims, claimType, claimValue);
- }
+ => await AuthenticateUserAndAssertClaimValue(claimType, claimValue);
}
diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Imgur/ImgurTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Imgur/ImgurTests.cs
index 80f7b959a..63fc08c8b 100644
--- a/test/AspNet.Security.OAuth.Providers.Tests/Imgur/ImgurTests.cs
+++ b/test/AspNet.Security.OAuth.Providers.Tests/Imgur/ImgurTests.cs
@@ -6,13 +6,8 @@
namespace AspNet.Security.OAuth.Imgur;
-public class ImgurTests : OAuthTests
+public class ImgurTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper)
{
- public ImgurTests(ITestOutputHelper outputHelper)
- {
- OutputHelper = outputHelper;
- }
-
public override string DefaultScheme => ImgurAuthenticationDefaults.AuthenticationScheme;
protected internal override void RegisterAuthentication(AuthenticationBuilder builder)
@@ -28,14 +23,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu
[InlineData("urn:imgur:proexpiration", "2019-03-17T14:00:00+00:00")]
[InlineData("urn:imgur:reputation", "0")]
public async Task Can_Sign_In_Using_Imgur(string claimType, string claimValue)
- {
- // Arrange
- using var server = CreateTestServer();
-
- // Act
- var claims = await AuthenticateUserAsync(server);
-
- // Assert
- AssertClaim(claims, claimType, claimValue);
- }
+ => await AuthenticateUserAndAssertClaimValue(claimType, claimValue);
}
diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Infrastructure/ApplicationFactory.cs b/test/AspNet.Security.OAuth.Providers.Tests/Infrastructure/ApplicationFactory.cs
index 17563ee27..9e7dd0424 100644
--- a/test/AspNet.Security.OAuth.Providers.Tests/Infrastructure/ApplicationFactory.cs
+++ b/test/AspNet.Security.OAuth.Providers.Tests/Infrastructure/ApplicationFactory.cs
@@ -97,8 +97,8 @@ private static void ConfigureApplication(IApplicationBuilder app, OAut
{
if (context.User.Identity?.IsAuthenticated == true)
{
- string xml = IdentityToXmlString(context.User);
- byte[] buffer = Encoding.UTF8.GetBytes(xml);
+ var xml = IdentityToXmlString(context.User);
+ var buffer = Encoding.UTF8.GetBytes(xml);
context.Response.StatusCode = 200;
context.Response.ContentType = "text/xml";
diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Infrastructure/HttpRequestInterceptionFilter.cs b/test/AspNet.Security.OAuth.Providers.Tests/Infrastructure/HttpRequestInterceptionFilter.cs
index 59f80cc6a..8116ad961 100644
--- a/test/AspNet.Security.OAuth.Providers.Tests/Infrastructure/HttpRequestInterceptionFilter.cs
+++ b/test/AspNet.Security.OAuth.Providers.Tests/Infrastructure/HttpRequestInterceptionFilter.cs
@@ -12,21 +12,14 @@ namespace AspNet.Security.OAuth.Infrastructure;
///
/// Registers an delegating handler to intercept HTTP requests made by the test application.
///
-internal sealed class HttpRequestInterceptionFilter : IHttpMessageHandlerBuilderFilter
+internal sealed class HttpRequestInterceptionFilter(HttpClientInterceptorOptions options) : IHttpMessageHandlerBuilderFilter
{
- private readonly HttpClientInterceptorOptions _options;
-
- internal HttpRequestInterceptionFilter(HttpClientInterceptorOptions options)
- {
- _options = options;
- }
-
public Action Configure(Action next)
{
return builder =>
{
next(builder);
- builder.AdditionalHandlers.Add(_options.CreateHttpMessageHandler());
+ builder.AdditionalHandlers.Add(options.CreateHttpMessageHandler());
};
}
}
diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Infrastructure/LoopbackRedirectHandler.cs b/test/AspNet.Security.OAuth.Providers.Tests/Infrastructure/LoopbackRedirectHandler.cs
index 5d3e94c4f..d170a46d7 100644
--- a/test/AspNet.Security.OAuth.Providers.Tests/Infrastructure/LoopbackRedirectHandler.cs
+++ b/test/AspNet.Security.OAuth.Providers.Tests/Infrastructure/LoopbackRedirectHandler.cs
@@ -35,7 +35,7 @@ protected override async Task SendAsync(HttpRequestMessage
if (RedirectMethod == HttpMethod.Post)
{
var queryString = HttpUtility.ParseQueryString(result.Headers.Location!.Query);
- string? state = queryString["state"];
+ var state = queryString["state"];
var parameters = new Dictionary()
{
@@ -86,17 +86,17 @@ protected virtual Uri BuildLoopbackUri(HttpResponseMessage responseMessage)
// successfully authenticated with the external login page they were redirected to.
var queryString = HttpUtility.ParseQueryString(responseMessage.Headers.Location!.Query);
- string? location = queryString["redirect_uri"] ?? RedirectUri;
- string? state = queryString["state"];
+ var location = queryString["redirect_uri"] ?? RedirectUri;
+ var state = queryString["state"];
var builder = new UriBuilder(location!);
// Retain the _oauthstate parameter in redirect_uri for WeChat (see #262)
const string OAuthStateKey = "_oauthstate";
var redirectQuery = HttpUtility.ParseQueryString(builder.Query);
- string? oauthState = redirectQuery[OAuthStateKey];
+ var oauthState = redirectQuery[OAuthStateKey];
- // Remove any query string parameters we do not explictly need to retain
+ // Remove any query string parameters we do not explicitly need to retain
queryString.Clear();
queryString.Add("code", "a6ed8e7f-471f-44f1-903b-65946475f351");
diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Instagram/InstagramTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Instagram/InstagramTests.cs
index 82a6c37e9..1ed0bdd41 100644
--- a/test/AspNet.Security.OAuth.Providers.Tests/Instagram/InstagramTests.cs
+++ b/test/AspNet.Security.OAuth.Providers.Tests/Instagram/InstagramTests.cs
@@ -8,13 +8,8 @@
namespace AspNet.Security.OAuth.Instagram;
-public class InstagramTests : OAuthTests
+public class InstagramTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper)
{
- public InstagramTests(ITestOutputHelper outputHelper)
- {
- OutputHelper = outputHelper;
- }
-
public override string DefaultScheme => InstagramAuthenticationDefaults.AuthenticationScheme;
protected internal override void RegisterAuthentication(AuthenticationBuilder builder)
@@ -26,16 +21,7 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu
[InlineData(ClaimTypes.Name, "jayposiris")]
[InlineData(ClaimTypes.NameIdentifier, "17841405793187218")]
public async Task Can_Sign_In_Using_Instagram(string claimType, string claimValue)
- {
- // Arrange
- using var server = CreateTestServer();
-
- // Act
- var claims = await AuthenticateUserAsync(server);
-
- // Assert
- AssertClaim(claims, claimType, claimValue);
- }
+ => await AuthenticateUserAndAssertClaimValue(claimType, claimValue);
[Theory]
[InlineData(ClaimTypes.Name, "jayposiris")]
@@ -55,12 +41,6 @@ static void ConfigureServices(IServiceCollection services)
});
}
- using var server = CreateTestServer(ConfigureServices);
-
- // Act
- var claims = await AuthenticateUserAsync(server);
-
- // Assert
- AssertClaim(claims, claimType, claimValue);
+ await AuthenticateUserAndAssertClaimValue(claimType, claimValue, ConfigureServices);
}
}
diff --git a/test/AspNet.Security.OAuth.Providers.Tests/JumpCloud/JumpCloudEnterpriseTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/JumpCloud/JumpCloudEnterpriseTests.cs
index 027be1b58..558139bb7 100644
--- a/test/AspNet.Security.OAuth.Providers.Tests/JumpCloud/JumpCloudEnterpriseTests.cs
+++ b/test/AspNet.Security.OAuth.Providers.Tests/JumpCloud/JumpCloudEnterpriseTests.cs
@@ -6,13 +6,8 @@
namespace AspNet.Security.OAuth.JumpCloud;
-public class JumpCloudEnterpriseTests : OAuthTests
+public class JumpCloudEnterpriseTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper)
{
- public JumpCloudEnterpriseTests(ITestOutputHelper outputHelper)
- {
- OutputHelper = outputHelper;
- }
-
public override string DefaultScheme => JumpCloudAuthenticationDefaults.AuthenticationScheme;
protected override string BundleName => "JumpCloud";
@@ -33,14 +28,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu
[InlineData(ClaimTypes.NameIdentifier, "00uid4BxXw6I6TV4m0g3")]
[InlineData(ClaimTypes.Surname, "Doe")]
public async Task Can_Sign_In_Using_JumpCloud(string claimType, string claimValue)
- {
- // Arrange
- using var server = CreateTestServer();
-
- // Act
- var claims = await AuthenticateUserAsync(server);
-
- // Assert
- AssertClaim(claims, claimType, claimValue);
- }
+ => await AuthenticateUserAndAssertClaimValue(claimType, claimValue);
}
diff --git a/test/AspNet.Security.OAuth.Providers.Tests/JumpCloud/JumpCloudTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/JumpCloud/JumpCloudTests.cs
index 1d3c849a2..8fa1e9e77 100644
--- a/test/AspNet.Security.OAuth.Providers.Tests/JumpCloud/JumpCloudTests.cs
+++ b/test/AspNet.Security.OAuth.Providers.Tests/JumpCloud/JumpCloudTests.cs
@@ -6,21 +6,13 @@
namespace AspNet.Security.OAuth.JumpCloud;
-public class JumpCloudTests : OAuthTests
+public class JumpCloudTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper)
{
- public JumpCloudTests(ITestOutputHelper outputHelper)
- {
- OutputHelper = outputHelper;
- }
-
public override string DefaultScheme => JumpCloudAuthenticationDefaults.AuthenticationScheme;
protected internal override void RegisterAuthentication(AuthenticationBuilder builder)
{
- builder.AddJumpCloud(options =>
- {
- ConfigureDefaults(builder, options);
- });
+ builder.AddJumpCloud(options => ConfigureDefaults(builder, options));
}
[Theory]
@@ -30,14 +22,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu
[InlineData(ClaimTypes.NameIdentifier, "00uid4BxXw6I6TV4m0g3")]
[InlineData(ClaimTypes.Surname, "Doe")]
public async Task Can_Sign_In_Using_JumpCloud(string claimType, string claimValue)
- {
- // Arrange
- using var server = CreateTestServer();
-
- // Act
- var claims = await AuthenticateUserAsync(server);
-
- // Assert
- AssertClaim(claims, claimType, claimValue);
- }
+ => await AuthenticateUserAndAssertClaimValue(claimType, claimValue);
}
diff --git a/test/AspNet.Security.OAuth.Providers.Tests/KakaoTalk/KakaoTalkTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/KakaoTalk/KakaoTalkTests.cs
index 55c4873ef..67c87b62d 100644
--- a/test/AspNet.Security.OAuth.Providers.Tests/KakaoTalk/KakaoTalkTests.cs
+++ b/test/AspNet.Security.OAuth.Providers.Tests/KakaoTalk/KakaoTalkTests.cs
@@ -8,13 +8,8 @@
namespace AspNet.Security.OAuth.KakaoTalk;
-public class KakaoTalkTests : OAuthTests
+public class KakaoTalkTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper)
{
- public KakaoTalkTests(ITestOutputHelper outputHelper)
- {
- OutputHelper = outputHelper;
- }
-
public override string DefaultScheme => KakaoTalkAuthenticationDefaults.AuthenticationScheme;
protected internal override void RegisterAuthentication(AuthenticationBuilder builder)
@@ -32,14 +27,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu
[InlineData(Claims.AgeRange, "20~29")]
[InlineData(Claims.YearOfBirth, "2020")]
public async Task Can_Sign_In_Using_KakaoTalk(string claimType, string claimValue)
- {
- // Arrange
- using var server = CreateTestServer();
-
- // Act
- var claims = await AuthenticateUserAsync(server);
-
- // Assert
- AssertClaim(claims, claimType, claimValue);
- }
+ => await AuthenticateUserAndAssertClaimValue(claimType, claimValue);
}
diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Keycloak/KeycloakTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Keycloak/KeycloakTests.cs
index e7f797c27..8d5d0d834 100644
--- a/test/AspNet.Security.OAuth.Providers.Tests/Keycloak/KeycloakTests.cs
+++ b/test/AspNet.Security.OAuth.Providers.Tests/Keycloak/KeycloakTests.cs
@@ -6,13 +6,8 @@
namespace AspNet.Security.OAuth.Keycloak;
-public class KeycloakTests : OAuthTests
+public class KeycloakTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper)
{
- public KeycloakTests(ITestOutputHelper outputHelper)
- {
- OutputHelper = outputHelper;
- }
-
public override string DefaultScheme => KeycloakAuthenticationDefaults.AuthenticationScheme;
protected internal override void RegisterAuthentication(AuthenticationBuilder builder)
@@ -42,13 +37,7 @@ static void ConfigureServices(IServiceCollection services)
});
}
- using var server = CreateTestServer(ConfigureServices);
-
- // Act
- var claims = await AuthenticateUserAsync(server);
-
- // Assert
- AssertClaim(claims, claimType, claimValue);
+ await AuthenticateUserAndAssertClaimValue(claimType, claimValue, ConfigureServices);
}
[Theory]
@@ -88,13 +77,7 @@ void ConfigureServices(IServiceCollection services)
});
}
- using var server = CreateTestServer(ConfigureServices);
-
- // Act
- var claims = await AuthenticateUserAsync(server);
-
- // Assert
- AssertClaim(claims, claimType, claimValue);
+ await AuthenticateUserAndAssertClaimValue(claimType, claimValue, ConfigureServices);
}
[Theory]
@@ -116,12 +99,6 @@ static void ConfigureServices(IServiceCollection services)
});
}
- using var server = CreateTestServer(ConfigureServices);
-
- // Act
- var claims = await AuthenticateUserAsync(server);
-
- // Assert
- AssertClaim(claims, claimType, claimValue);
+ await AuthenticateUserAndAssertClaimValue(claimType, claimValue, ConfigureServices);
}
}
diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Kloudless/KloudlessTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Kloudless/KloudlessTests.cs
index eea4e497e..f4dd1ac24 100644
--- a/test/AspNet.Security.OAuth.Providers.Tests/Kloudless/KloudlessTests.cs
+++ b/test/AspNet.Security.OAuth.Providers.Tests/Kloudless/KloudlessTests.cs
@@ -6,13 +6,8 @@
namespace AspNet.Security.OAuth.Kloudless;
-public class KloudlessTests : OAuthTests
+public class KloudlessTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper)
{
- public KloudlessTests(ITestOutputHelper outputHelper)
- {
- OutputHelper = outputHelper;
- }
-
public override string DefaultScheme => KloudlessAuthenticationDefaults.AuthenticationScheme;
protected internal override void RegisterAuthentication(AuthenticationBuilder builder)
@@ -34,14 +29,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu
[InlineData(KloudlessAuthenticationConstants.Claims.Type, "account")]
[InlineData(KloudlessAuthenticationConstants.Claims.Enabled, "True")]
public async Task Can_Sign_In_Using_Kloudless(string claimType, string claimValue)
- {
- // Arrange
- using var server = CreateTestServer();
-
- // Act
- var claims = await AuthenticateUserAsync(server);
-
- // Assert
- AssertClaim(claims, claimType, claimValue);
- }
+ => await AuthenticateUserAndAssertClaimValue(claimType, claimValue);
}
diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Kook/KookTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Kook/KookTests.cs
index 0bcaf219b..6f44cd16f 100644
--- a/test/AspNet.Security.OAuth.Providers.Tests/Kook/KookTests.cs
+++ b/test/AspNet.Security.OAuth.Providers.Tests/Kook/KookTests.cs
@@ -8,13 +8,8 @@
namespace AspNet.Security.OAuth.Kook;
-public class KookTests : OAuthTests
+public class KookTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper)
{
- public KookTests(ITestOutputHelper outputHelper)
- {
- OutputHelper = outputHelper;
- }
-
public override string DefaultScheme => KookAuthenticationDefaults.AuthenticationScheme;
protected internal override void RegisterAuthentication(AuthenticationBuilder builder)
@@ -32,14 +27,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu
[InlineData(Claims.BannerUrl, "https://xxx.com/assets/banner.png/icon")]
[InlineData(Claims.IsMobileVerified, "True")]
public async Task Can_Sign_In_Using_Kook(string claimType, string claimValue)
- {
- // Arrange
- using var server = CreateTestServer();
-
- // Act
- var claims = await AuthenticateUserAsync(server);
-
- // Assert
- AssertClaim(claims, claimType, claimValue);
- }
+ => await AuthenticateUserAndAssertClaimValue(claimType, claimValue);
}
diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Kroger/KrogerTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Kroger/KrogerTests.cs
index cea9b885a..ef4f87e8c 100644
--- a/test/AspNet.Security.OAuth.Providers.Tests/Kroger/KrogerTests.cs
+++ b/test/AspNet.Security.OAuth.Providers.Tests/Kroger/KrogerTests.cs
@@ -6,13 +6,8 @@
namespace AspNet.Security.OAuth.Kroger;
-public class KrogerTests : OAuthTests
+public class KrogerTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper)
{
- public KrogerTests(ITestOutputHelper outputHelper)
- {
- OutputHelper = outputHelper;
- }
-
public override string DefaultScheme => KrogerAuthenticationDefaults.AuthenticationScheme;
protected internal override void RegisterAuthentication(AuthenticationBuilder builder)
@@ -23,14 +18,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu
[Theory]
[InlineData(ClaimTypes.NameIdentifier, "53990804-cfd1-43f3-8256-bdc9817a4fd0")]
public async Task Can_Sign_In_Using_Kroger(string claimType, string claimValue)
- {
- // Arrange
- using var server = CreateTestServer();
-
- // Act
- var claims = await AuthenticateUserAsync(server);
-
- // Assert
- AssertClaim(claims, claimType, claimValue);
- }
+ => await AuthenticateUserAndAssertClaimValue(claimType, claimValue);
}
diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Lichess/LichessTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Lichess/LichessTests.cs
index 7f58b92e3..f3b2ed941 100644
--- a/test/AspNet.Security.OAuth.Providers.Tests/Lichess/LichessTests.cs
+++ b/test/AspNet.Security.OAuth.Providers.Tests/Lichess/LichessTests.cs
@@ -6,13 +6,8 @@
namespace AspNet.Security.OAuth.Lichess;
-public class LichessTests : OAuthTests
+public class LichessTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper)
{
- public LichessTests(ITestOutputHelper outputHelper)
- {
- OutputHelper = outputHelper;
- }
-
public override string DefaultScheme => LichessAuthenticationDefaults.AuthenticationScheme;
protected internal override void RegisterAuthentication(AuthenticationBuilder builder)
@@ -31,14 +26,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu
[InlineData(ClaimTypes.GivenName, "Thibault")]
[InlineData(ClaimTypes.Surname, "Duplessis")]
public async Task Can_Sign_In_Using_Lichess(string claimType, string claimValue)
- {
- // Arrange
- using var server = CreateTestServer();
-
- // Act
- var claims = await AuthenticateUserAsync(server);
-
- // Assert
- AssertClaim(claims, claimType, claimValue);
- }
+ => await AuthenticateUserAndAssertClaimValue(claimType, claimValue);
}
diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Line/LineTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Line/LineTests.cs
index 6c5fe34f5..1b85a071f 100644
--- a/test/AspNet.Security.OAuth.Providers.Tests/Line/LineTests.cs
+++ b/test/AspNet.Security.OAuth.Providers.Tests/Line/LineTests.cs
@@ -8,15 +8,10 @@
namespace AspNet.Security.OAuth.Line;
-public class LineTests : OAuthTests
+public class LineTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper)
{
public override string DefaultScheme => LineAuthenticationDefaults.AuthenticationScheme;
- public LineTests(ITestOutputHelper outputHelper)
- {
- OutputHelper = outputHelper;
- }
-
protected internal override void RegisterAuthentication(AuthenticationBuilder builder)
{
builder.AddLine(options =>
@@ -32,16 +27,7 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu
[InlineData("urn:line:picture_url", "my-picture")]
[InlineData(ClaimTypes.Email, "my-email")]
public async Task Can_Sign_In_Using_Line(string claimType, string claimValue)
- {
- // Arrange
- using var server = CreateTestServer();
-
- // Act
- var claims = await AuthenticateUserAsync(server);
-
- // Assert
- AssertClaim(claims, claimType, claimValue);
- }
+ => await AuthenticateUserAndAssertClaimValue(claimType, claimValue);
[Theory]
[InlineData(false, false)]
diff --git a/test/AspNet.Security.OAuth.Providers.Tests/LinkedIn/LinkedInTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/LinkedIn/LinkedInTests.cs
index bd476412b..8f8956a5d 100644
--- a/test/AspNet.Security.OAuth.Providers.Tests/LinkedIn/LinkedInTests.cs
+++ b/test/AspNet.Security.OAuth.Providers.Tests/LinkedIn/LinkedInTests.cs
@@ -8,15 +8,10 @@
namespace AspNet.Security.OAuth.LinkedIn;
-public class LinkedInTests : OAuthTests
+public class LinkedInTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper)
{
private Action? additionalConfiguration;
- public LinkedInTests(ITestOutputHelper outputHelper)
- {
- OutputHelper = outputHelper;
- }
-
public override string DefaultScheme => LinkedInAuthenticationDefaults.AuthenticationScheme;
protected internal override void RegisterAuthentication(AuthenticationBuilder builder)
@@ -48,13 +43,7 @@ public async Task Can_Sign_In_Using_LinkedIn(string claimType, string claimValue
// Arrange
additionalConfiguration = options => options.Fields.Add(LinkedInAuthenticationConstants.ProfileFields.PictureUrl);
- using var server = CreateTestServer();
-
- // Act
- var claims = await AuthenticateUserAsync(server);
-
- // Assert
- AssertClaim(claims, claimType, claimValue);
+ await AuthenticateUserAndAssertClaimValue(claimType, claimValue);
}
[Theory]
@@ -63,16 +52,7 @@ public async Task Can_Sign_In_Using_LinkedIn(string claimType, string claimValue
[InlineData(ClaimTypes.GivenName, "Frodon")]
[InlineData(ClaimTypes.Surname, "Sacquet")]
public async Task Can_Sign_In_Using_LinkedIn_Localized(string claimType, string claimValue)
- {
- // Arrange
- using var server = CreateTestServer();
-
- // Act
- var claims = await AuthenticateUserAsync(server);
-
- // Assert
- AssertClaim(claims, claimType, claimValue);
- }
+ => await AuthenticateUserAndAssertClaimValue(claimType, claimValue);
[Theory]
[InlineData(ClaimTypes.NameIdentifier, "1R2RtA")]
@@ -84,7 +64,7 @@ public async Task Can_Sign_In_Using_LinkedIn_Localized_With_Custom_Resolver(stri
// Arrange
additionalConfiguration = options => options.MultiLocaleStringResolver = (values, preferredLocale) =>
{
- if (values.TryGetValue("fr_FR", out string? value))
+ if (values.TryGetValue("fr_FR", out var value))
{
return value;
}
@@ -92,12 +72,6 @@ public async Task Can_Sign_In_Using_LinkedIn_Localized_With_Custom_Resolver(stri
return values.Values.FirstOrDefault();
};
- using var server = CreateTestServer();
-
- // Act
- var claims = await AuthenticateUserAsync(server);
-
- // Assert
- AssertClaim(claims, claimType, claimValue);
+ await AuthenticateUserAndAssertClaimValue(claimType, claimValue);
}
}
diff --git a/test/AspNet.Security.OAuth.Providers.Tests/MailChimp/MailChimpTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/MailChimp/MailChimpTests.cs
index 78d7ed00b..9de5447d3 100644
--- a/test/AspNet.Security.OAuth.Providers.Tests/MailChimp/MailChimpTests.cs
+++ b/test/AspNet.Security.OAuth.Providers.Tests/MailChimp/MailChimpTests.cs
@@ -6,13 +6,8 @@
namespace AspNet.Security.OAuth.MailChimp;
-public class MailChimpTests : OAuthTests
+public class MailChimpTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper)
{
- public MailChimpTests(ITestOutputHelper outputHelper)
- {
- OutputHelper = outputHelper;
- }
-
public override string DefaultScheme => MailChimpAuthenticationDefaults.AuthenticationScheme;
protected internal override void RegisterAuthentication(AuthenticationBuilder builder)
@@ -25,14 +20,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu
[InlineData(ClaimTypes.Name, "John Smith")]
[InlineData(ClaimTypes.Email, "john@john-smith.local")]
public async Task Can_Sign_In_Using_MailChimp(string claimType, string claimValue)
- {
- // Arrange
- using var server = CreateTestServer();
-
- // Act
- var claims = await AuthenticateUserAsync(server);
-
- // Assert
- AssertClaim(claims, claimType, claimValue);
- }
+ => await AuthenticateUserAndAssertClaimValue(claimType, claimValue);
}
diff --git a/test/AspNet.Security.OAuth.Providers.Tests/MailRu/MailRuTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/MailRu/MailRuTests.cs
index e412e0acd..d95f6676e 100644
--- a/test/AspNet.Security.OAuth.Providers.Tests/MailRu/MailRuTests.cs
+++ b/test/AspNet.Security.OAuth.Providers.Tests/MailRu/MailRuTests.cs
@@ -6,21 +6,13 @@
namespace AspNet.Security.OAuth.MailRu;
-public class MailRuTests : OAuthTests
+public class MailRuTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper)
{
- public MailRuTests(ITestOutputHelper outputHelper)
- {
- OutputHelper = outputHelper;
- }
-
public override string DefaultScheme => MailRuAuthenticationDefaults.AuthenticationScheme;
protected internal override void RegisterAuthentication(AuthenticationBuilder builder)
{
- builder.AddMailRu(options =>
- {
- ConfigureDefaults(builder, options);
- });
+ builder.AddMailRu(options => ConfigureDefaults(builder, options));
}
[Theory]
@@ -32,14 +24,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu
[InlineData(ClaimTypes.Gender, "m")]
[InlineData("urn:mailru:profileimage", "https://filin.mail.ru/pic?d=idofpic&width=180&height=180")]
public async Task Can_Sign_In_Using_MailRu(string claimType, string claimValue)
- {
- // Arrange
- using var server = CreateTestServer();
-
- // Act
- var claims = await AuthenticateUserAsync(server);
-
- // Assert
- AssertClaim(claims, claimType, claimValue);
- }
+ => await AuthenticateUserAndAssertClaimValue(claimType, claimValue);
}
diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Mixcloud/MixcloudTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Mixcloud/MixcloudTests.cs
index ee1fa8d9b..285bc508d 100644
--- a/test/AspNet.Security.OAuth.Providers.Tests/Mixcloud/MixcloudTests.cs
+++ b/test/AspNet.Security.OAuth.Providers.Tests/Mixcloud/MixcloudTests.cs
@@ -8,13 +8,8 @@
namespace AspNet.Security.OAuth.Mixcloud;
-public class MixcloudTests : OAuthTests
+public class MixcloudTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper)
{
- public MixcloudTests(ITestOutputHelper outputHelper)
- {
- OutputHelper = outputHelper;
- }
-
public override string DefaultScheme => MixcloudAuthenticationDefaults.AuthenticationScheme;
protected internal override void RegisterAuthentication(AuthenticationBuilder builder)
@@ -33,16 +28,7 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu
[InlineData("urn:mixcloud:profileimageurl", "https://mixcloud.local/images/320wx320h")]
[InlineData("urn:mixcloud:profilethumbnailurl", "https://mixcloud.local/images/thumbnail")]
public async Task Can_Sign_In_Using_Mixcloud(string claimType, string claimValue)
- {
- // Arrange
- using var server = CreateTestServer();
-
- // Act
- var claims = await AuthenticateUserAsync(server);
-
- // Assert
- AssertClaim(claims, claimType, claimValue);
- }
+ => await AuthenticateUserAndAssertClaimValue(claimType, claimValue);
[Theory]
[InlineData(false)]
diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Moodle/MoodleTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Moodle/MoodleTests.cs
index e232581c0..f68aeaa18 100644
--- a/test/AspNet.Security.OAuth.Providers.Tests/Moodle/MoodleTests.cs
+++ b/test/AspNet.Security.OAuth.Providers.Tests/Moodle/MoodleTests.cs
@@ -8,13 +8,8 @@
namespace AspNet.Security.OAuth.Moodle;
-public class MoodleTests : OAuthTests
+public class MoodleTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper)
{
- public MoodleTests(ITestOutputHelper outputHelper)
- {
- OutputHelper = outputHelper;
- }
-
public override string DefaultScheme => MoodleAuthenticationDefaults.AuthenticationScheme;
protected internal override void RegisterAuthentication(AuthenticationBuilder builder)
@@ -40,16 +35,7 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu
[InlineData(Claims.Language, "en")]
[InlineData(Claims.Description, "John Doe's Moodle account")]
public async Task Can_Sign_In_Using_Moodle(string claimType, string claimValue)
- {
- // Arrange
- using var server = CreateTestServer();
-
- // Act
- var claims = await AuthenticateUserAsync(server);
-
- // Assert
- AssertClaim(claims, claimType, claimValue);
- }
+ => await AuthenticateUserAndAssertClaimValue(claimType, claimValue);
[Theory]
[InlineData(ClaimTypes.Name, "张三")]
@@ -80,12 +66,6 @@ static void ConfigureServices(IServiceCollection services)
});
}
- using var server = CreateTestServer(ConfigureServices);
-
- // Act
- var claims = await AuthenticateUserAsync(server);
-
- // Assert
- AssertClaim(claims, claimType, claimValue);
+ await AuthenticateUserAndAssertClaimValue(claimType, claimValue, ConfigureServices);
}
}
diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Myob/MyobTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Myob/MyobTests.cs
index 3b1d8033e..c69a40519 100644
--- a/test/AspNet.Security.OAuth.Providers.Tests/Myob/MyobTests.cs
+++ b/test/AspNet.Security.OAuth.Providers.Tests/Myob/MyobTests.cs
@@ -6,13 +6,8 @@
namespace AspNet.Security.OAuth.Myob;
-public class MyobTests : OAuthTests
+public class MyobTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper)
{
- public MyobTests(ITestOutputHelper outputHelper)
- {
- OutputHelper = outputHelper;
- }
-
public override string DefaultScheme => MyobAuthenticationDefaults.AuthenticationScheme;
protected internal override void RegisterAuthentication(AuthenticationBuilder builder)
@@ -24,14 +19,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu
[InlineData(ClaimTypes.NameIdentifier, "my-id")]
[InlineData(ClaimTypes.Name, "John Smith")]
public async Task Can_Sign_In_Using_Myob(string claimType, string claimValue)
- {
- // Arrange
- using var server = CreateTestServer();
-
- // Act
- var claims = await AuthenticateUserAsync(server);
-
- // Assert
- AssertClaim(claims, claimType, claimValue);
- }
+ => await AuthenticateUserAndAssertClaimValue(claimType, claimValue);
}
diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Naver/NaverTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Naver/NaverTests.cs
index a5c41361b..ea52901a4 100644
--- a/test/AspNet.Security.OAuth.Providers.Tests/Naver/NaverTests.cs
+++ b/test/AspNet.Security.OAuth.Providers.Tests/Naver/NaverTests.cs
@@ -8,13 +8,8 @@
namespace AspNet.Security.OAuth.Naver;
-public class NaverTests : OAuthTests
+public class NaverTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper)
{
- public NaverTests(ITestOutputHelper outputHelper)
- {
- OutputHelper = outputHelper;
- }
-
public override string DefaultScheme => NaverAuthenticationDefaults.AuthenticationScheme;
protected internal override void RegisterAuthentication(AuthenticationBuilder builder)
@@ -34,14 +29,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu
[InlineData(Claims.YearOfBirth, "2020")]
[InlineData(Claims.ProfileImage, "https://ssl.pstatic.net/static/pwe/address/img_profile.png")]
public async Task Can_Sign_In_Using_Naver(string claimType, string claimValue)
- {
- // Arrange
- using var server = CreateTestServer();
-
- // Act
- var claims = await AuthenticateUserAsync(server);
-
- // Assert
- AssertClaim(claims, claimType, claimValue);
- }
+ => await AuthenticateUserAndAssertClaimValue(claimType, claimValue);
}
diff --git a/test/AspNet.Security.OAuth.Providers.Tests/NetEase/NetEaseTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/NetEase/NetEaseTests.cs
index 6679d5c87..052ff657c 100644
--- a/test/AspNet.Security.OAuth.Providers.Tests/NetEase/NetEaseTests.cs
+++ b/test/AspNet.Security.OAuth.Providers.Tests/NetEase/NetEaseTests.cs
@@ -6,13 +6,8 @@
namespace AspNet.Security.OAuth.NetEase;
-public class NetEaseTests : OAuthTests
+public class NetEaseTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper)
{
- public NetEaseTests(ITestOutputHelper outputHelper)
- {
- OutputHelper = outputHelper;
- }
-
public override string DefaultScheme => NetEaseAuthenticationDefaults.AuthenticationScheme;
protected internal override void RegisterAuthentication(AuthenticationBuilder builder)
@@ -24,14 +19,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu
[InlineData(ClaimTypes.NameIdentifier, "820014421")]
[InlineData(ClaimTypes.Name, "urstest_mreg")]
public async Task Can_Sign_In_Using_NetEase(string claimType, string claimValue)
- {
- // Arrange
- using var server = CreateTestServer();
-
- // Act
- var claims = await AuthenticateUserAsync(server);
-
- // Assert
- AssertClaim(claims, claimType, claimValue);
- }
+ => await AuthenticateUserAndAssertClaimValue(claimType, claimValue);
}
diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Nextcloud/NextcloudTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Nextcloud/NextcloudTests.cs
index 980d438f0..efc71afe6 100644
--- a/test/AspNet.Security.OAuth.Providers.Tests/Nextcloud/NextcloudTests.cs
+++ b/test/AspNet.Security.OAuth.Providers.Tests/Nextcloud/NextcloudTests.cs
@@ -6,13 +6,8 @@
namespace AspNet.Security.OAuth.Nextcloud;
-public class NextcloudTests : OAuthTests
+public class NextcloudTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper)
{
- public NextcloudTests(ITestOutputHelper outputHelper)
- {
- OutputHelper = outputHelper;
- }
-
public override string DefaultScheme => NextcloudAuthenticationDefaults.AuthenticationScheme;
protected internal override void RegisterAuthentication(AuthenticationBuilder builder)
@@ -36,14 +31,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu
[InlineData("urn:nextcloud:language", "de")]
[InlineData("urn:nextcloud:locale", "de_DE")]
public async Task Can_Sign_In_Using_Nextcloud(string claimType, string claimValue)
- {
- // Arrange
- using var server = CreateTestServer();
-
- // Act
- var claims = await AuthenticateUserAsync(server);
-
- // Assert
- AssertClaim(claims, claimType, claimValue);
- }
+ => await AuthenticateUserAndAssertClaimValue(claimType, claimValue);
}
diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Notion/NotionTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Notion/NotionTests.cs
index 3af6e785b..ca20113d3 100644
--- a/test/AspNet.Security.OAuth.Providers.Tests/Notion/NotionTests.cs
+++ b/test/AspNet.Security.OAuth.Providers.Tests/Notion/NotionTests.cs
@@ -6,21 +6,13 @@
namespace AspNet.Security.OAuth.Notion;
-public class NotionTests : OAuthTests
+public class NotionTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper)
{
- public NotionTests(ITestOutputHelper outputHelper)
- {
- OutputHelper = outputHelper;
- }
-
public override string DefaultScheme => NotionAuthenticationDefaults.AuthenticationScheme;
protected internal override void RegisterAuthentication(AuthenticationBuilder builder)
{
- builder.AddNotion(options =>
- {
- ConfigureDefaults(builder, options);
- });
+ builder.AddNotion(options => ConfigureDefaults(builder, options));
}
[Theory]
@@ -28,14 +20,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu
[InlineData("urn:notion:workspace_icon", "icon")]
[InlineData("urn:notion:bot_id", "mybot")]
public async Task Can_Sign_In_Using_Notion(string claimType, string claimValue)
- {
- // Arrange
- using var server = CreateTestServer();
-
- // Act
- var claims = await AuthenticateUserAsync(server);
-
- // Assert
- AssertClaim(claims, claimType, claimValue);
- }
+ => await AuthenticateUserAndAssertClaimValue(claimType, claimValue);
}
diff --git a/test/AspNet.Security.OAuth.Providers.Tests/OAuthTests`1.cs b/test/AspNet.Security.OAuth.Providers.Tests/OAuthTests`1.cs
index c62cc12aa..b445a2d11 100644
--- a/test/AspNet.Security.OAuth.Providers.Tests/OAuthTests`1.cs
+++ b/test/AspNet.Security.OAuth.Providers.Tests/OAuthTests`1.cs
@@ -31,7 +31,7 @@ namespace AspNet.Security.OAuth;
public abstract class OAuthTests : ITestOutputHelperAccessor
where TOptions : OAuthOptions, new()
{
- protected OAuthTests()
+ protected OAuthTests(ITestOutputHelper outputHelper)
{
Interceptor = new HttpClientInterceptorOptions()
.ThrowsOnMissingRegistration()
@@ -43,6 +43,8 @@ protected OAuthTests()
RedirectParameters = RedirectParameters,
RedirectUri = RedirectUri,
};
+
+ OutputHelper = outputHelper;
}
///
@@ -94,6 +96,19 @@ protected OAuthTests()
/// The application.
protected internal virtual void ConfigureApplication(IApplicationBuilder app)
{
+ // No-op
+ }
+
+ protected async Task AuthenticateUserAndAssertClaimValue(string claimType, string claimValue, Action? configureServices = null)
+ {
+ // Arrange
+ using var server = CreateTestServer(configureServices);
+
+ // Act
+ var claims = await AuthenticateUserAsync(server);
+
+ // Assert
+ AssertClaim(claims, claimType, claimValue);
}
///
@@ -329,7 +344,7 @@ protected async Task BuildChallengeUriAsync(
var dataProtector = Substitute.For();
dataProtector.Protect(Arg.Any())
- .Returns(Array.Empty());
+ .Returns([]);
options.StateDataFormat ??= new PropertiesDataFormat(dataProtector);
}
diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Odnoklassniki/OdnoklassnikiTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Odnoklassniki/OdnoklassnikiTests.cs
index 06ca89886..fe03ec707 100644
--- a/test/AspNet.Security.OAuth.Providers.Tests/Odnoklassniki/OdnoklassnikiTests.cs
+++ b/test/AspNet.Security.OAuth.Providers.Tests/Odnoklassniki/OdnoklassnikiTests.cs
@@ -8,13 +8,8 @@
namespace AspNet.Security.OAuth.Odnoklassniki;
-public class OdnoklassnikiTests : OAuthTests
+public class OdnoklassnikiTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper)
{
- public OdnoklassnikiTests(ITestOutputHelper outputHelper)
- {
- OutputHelper = outputHelper;
- }
-
public override string DefaultScheme => OdnoklassnikiAuthenticationDefaults.AuthenticationScheme;
protected internal override void RegisterAuthentication(AuthenticationBuilder builder)
@@ -39,16 +34,7 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu
[InlineData("urn:ok:image2", "https://i.mycdn.me/res/stub_128x96.gif")]
[InlineData("urn:ok:image3", "https://i.mycdn.me/res/stub_128x96.gif")]
public async Task Can_Sign_In_Using_Odnoklassniki(string claimType, string claimValue)
- {
- // Arrange
- using var server = CreateTestServer();
-
- // Act
- var claims = await AuthenticateUserAsync(server);
-
- // Assert
- AssertClaim(claims, claimType, claimValue);
- }
+ => await AuthenticateUserAndAssertClaimValue(claimType, claimValue);
[Theory]
[InlineData(false)]
diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Okta/OktaTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Okta/OktaTests.cs
index f27966d8b..cd953ca8d 100644
--- a/test/AspNet.Security.OAuth.Providers.Tests/Okta/OktaTests.cs
+++ b/test/AspNet.Security.OAuth.Providers.Tests/Okta/OktaTests.cs
@@ -6,13 +6,8 @@
namespace AspNet.Security.OAuth.Okta;
-public class OktaTests : OAuthTests
+public class OktaTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper)
{
- public OktaTests(ITestOutputHelper outputHelper)
- {
- OutputHelper = outputHelper;
- }
-
public override string DefaultScheme => OktaAuthenticationDefaults.AuthenticationScheme;
protected internal override void RegisterAuthentication(AuthenticationBuilder builder)
@@ -31,16 +26,7 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu
[InlineData(ClaimTypes.NameIdentifier, "00uid4BxXw6I6TV4m0g3")]
[InlineData(ClaimTypes.Surname, "Doe")]
public async Task Can_Sign_In_Using_Okta(string claimType, string claimValue)
- {
- // Arrange
- using var server = CreateTestServer();
-
- // Act
- var claims = await AuthenticateUserAsync(server);
-
- // Assert
- AssertClaim(claims, claimType, claimValue);
- }
+ => await AuthenticateUserAndAssertClaimValue(claimType, claimValue);
[Theory]
[InlineData(ClaimTypes.Email, "jane.doe@example.com")]
@@ -59,12 +45,6 @@ static void ConfigureServices(IServiceCollection services)
});
}
- using var server = CreateTestServer(ConfigureServices);
-
- // Act
- var claims = await AuthenticateUserAsync(server);
-
- // Assert
- AssertClaim(claims, claimType, claimValue);
+ await AuthenticateUserAndAssertClaimValue(claimType, claimValue, ConfigureServices);
}
}
diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Onshape/OnshapeTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Onshape/OnshapeTests.cs
index ad68474ea..7dcb4f15b 100644
--- a/test/AspNet.Security.OAuth.Providers.Tests/Onshape/OnshapeTests.cs
+++ b/test/AspNet.Security.OAuth.Providers.Tests/Onshape/OnshapeTests.cs
@@ -6,13 +6,8 @@
namespace AspNet.Security.OAuth.Onshape;
-public class OnshapeTests : OAuthTests
+public class OnshapeTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper)
{
- public OnshapeTests(ITestOutputHelper outputHelper)
- {
- OutputHelper = outputHelper;
- }
-
public override string DefaultScheme => OnshapeAuthenticationDefaults.AuthenticationScheme;
protected internal override void RegisterAuthentication(AuthenticationBuilder builder)
@@ -24,14 +19,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu
[InlineData(ClaimTypes.NameIdentifier, "my-id")]
[InlineData(ClaimTypes.Name, "John Smith")]
public async Task Can_Sign_In_Using_Onshape(string claimType, string claimValue)
- {
- // Arrange
- using var server = CreateTestServer();
-
- // Act
- var claims = await AuthenticateUserAsync(server);
-
- // Assert
- AssertClaim(claims, claimType, claimValue);
- }
+ => await AuthenticateUserAndAssertClaimValue(claimType, claimValue);
}
diff --git a/test/AspNet.Security.OAuth.Providers.Tests/PackageMetadataTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/PackageMetadataTests.cs
index 03c2196d5..8024caf72 100644
--- a/test/AspNet.Security.OAuth.Providers.Tests/PackageMetadataTests.cs
+++ b/test/AspNet.Security.OAuth.Providers.Tests/PackageMetadataTests.cs
@@ -19,13 +19,13 @@ public static class PackageMetadataTests
public static IEnumerable