diff --git a/src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreHandler.cs b/src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreHandler.cs index 2d546cde..3aa88910 100644 --- a/src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreHandler.cs +++ b/src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreHandler.cs @@ -135,6 +135,14 @@ public sealed class OpenIddictClientAspNetCoreHandler : AuthenticationHandler { [Properties.Error] = context.Error, @@ -147,11 +155,6 @@ public sealed class OpenIddictClientAspNetCoreHandler : AuthenticationHandler protected override async Task TeardownCoreAsync() { - // Note: OWIN authentication handlers cannot reliabily write to the response stream + // Note: OWIN authentication handlers cannot reliably write to the response stream // from ApplyResponseGrantAsync() or ApplyResponseChallengeAsync() because these methods // are susceptible to be invoked from AuthenticationHandler.OnSendingHeaderCallback(), // where calling Write() or WriteAsync() on the response stream may result in a deadlock diff --git a/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandler.cs b/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandler.cs index 847fa2be..10bc310e 100644 --- a/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandler.cs +++ b/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandler.cs @@ -186,15 +186,10 @@ public sealed class OpenIddictServerAspNetCoreHandler : AuthenticationHandler null }; - if (principal is null) - { - return AuthenticateResult.NoResult(); - } - // Restore or create a new authentication properties collection and populate it. var properties = CreateProperties(principal); - properties.ExpiresUtc = principal.GetExpirationDate(); - properties.IssuedUtc = principal.GetCreationDate(); + properties.ExpiresUtc = principal?.GetExpirationDate(); + properties.IssuedUtc = principal?.GetCreationDate(); List? tokens = null; @@ -311,7 +306,8 @@ public sealed class OpenIddictServerAspNetCoreHandler : AuthenticationHandler null }; - if (principal is null) - { - return null; - } - // Restore or create a new authentication properties collection and populate it. var properties = CreateProperties(principal); - properties.ExpiresUtc = principal.GetExpirationDate(); - properties.IssuedUtc = principal.GetCreationDate(); + properties.ExpiresUtc = principal?.GetExpirationDate(); + properties.IssuedUtc = principal?.GetCreationDate(); // Attach the tokens to allow any OWIN component (e.g a controller) // to retrieve them (e.g to make an API request to another application). @@ -240,7 +235,7 @@ public sealed class OpenIddictServerOwinHandler : AuthenticationHandler protected override async Task TeardownCoreAsync() { - // Note: OWIN authentication handlers cannot reliabily write to the response stream + // Note: OWIN authentication handlers cannot reliably write to the response stream // from ApplyResponseGrantAsync() or ApplyResponseChallengeAsync() because these methods // are susceptible to be invoked from AuthenticationHandler.OnSendingHeaderCallback(), // where calling Write() or WriteAsync() on the response stream may result in a deadlock diff --git a/src/OpenIddict.Validation.AspNetCore/OpenIddictValidationAspNetCoreHandler.cs b/src/OpenIddict.Validation.AspNetCore/OpenIddictValidationAspNetCoreHandler.cs index ee977f81..5f7949b9 100644 --- a/src/OpenIddict.Validation.AspNetCore/OpenIddictValidationAspNetCoreHandler.cs +++ b/src/OpenIddict.Validation.AspNetCore/OpenIddictValidationAspNetCoreHandler.cs @@ -5,6 +5,7 @@ */ using System.ComponentModel; +using System.Security.Claims; using System.Text.Encodings.Web; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; @@ -162,15 +163,10 @@ public sealed class OpenIddictValidationAspNetCoreHandler : AuthenticationHandle _ => null }; - if (principal is null) - { - return AuthenticateResult.NoResult(); - } - var properties = new AuthenticationProperties { - ExpiresUtc = principal.GetExpirationDate(), - IssuedUtc = principal.GetCreationDate() + ExpiresUtc = principal?.GetExpirationDate(), + IssuedUtc = principal?.GetCreationDate() }; List? tokens = null; @@ -198,7 +194,8 @@ public sealed class OpenIddictValidationAspNetCoreHandler : AuthenticationHandle properties.StoreTokens(tokens); } - return AuthenticateResult.Success(new AuthenticationTicket(principal, properties, + return AuthenticateResult.Success(new AuthenticationTicket( + principal ?? new ClaimsPrincipal(new ClaimsIdentity()), properties, OpenIddictValidationAspNetCoreDefaults.AuthenticationScheme)); } } diff --git a/src/OpenIddict.Validation.Owin/OpenIddictValidationOwinHandler.cs b/src/OpenIddict.Validation.Owin/OpenIddictValidationOwinHandler.cs index 93b5e653..8d81df9b 100644 --- a/src/OpenIddict.Validation.Owin/OpenIddictValidationOwinHandler.cs +++ b/src/OpenIddict.Validation.Owin/OpenIddictValidationOwinHandler.cs @@ -170,15 +170,10 @@ public sealed class OpenIddictValidationOwinHandler : AuthenticationHandler null }; - if (principal is null) - { - return null; - } - var properties = new AuthenticationProperties { - ExpiresUtc = principal.GetExpirationDate(), - IssuedUtc = principal.GetCreationDate() + ExpiresUtc = principal?.GetExpirationDate(), + IssuedUtc = principal?.GetCreationDate() }; // Attach the tokens to allow any OWIN/Katana component (e.g a controller) @@ -189,14 +184,14 @@ public sealed class OpenIddictValidationOwinHandler : AuthenticationHandler protected override async Task TeardownCoreAsync() { - // Note: OWIN authentication handlers cannot reliabily write to the response stream + // Note: OWIN authentication handlers cannot reliably write to the response stream // from ApplyResponseGrantAsync() or ApplyResponseChallengeAsync() because these methods // are susceptible to be invoked from AuthenticationHandler.OnSendingHeaderCallback(), // where calling Write() or WriteAsync() on the response stream may result in a deadlock