Browse Source

Make Handle*RequestContext.Principal non-nullable for introspection, revocation and userinfo requests

pull/1315/head
Kévin Chalet 4 years ago
parent
commit
fd9d376a0a
  1. 16
      src/OpenIddict.Core/OpenIddictCoreBuilder.cs
  2. 2
      src/OpenIddict.Server/OpenIddictServerEvents.Introspection.cs
  3. 2
      src/OpenIddict.Server/OpenIddictServerEvents.Revocation.cs
  4. 2
      src/OpenIddict.Server/OpenIddictServerEvents.Userinfo.cs
  5. 2
      src/OpenIddict.Server/OpenIddictServerHandlers.Introspection.cs
  6. 2
      src/OpenIddict.Server/OpenIddictServerHandlers.Revocation.cs
  7. 2
      src/OpenIddict.Server/OpenIddictServerHandlers.Userinfo.cs
  8. 6
      src/OpenIddict.Server/OpenIddictServerHandlers.cs

16
src/OpenIddict.Core/OpenIddictCoreBuilder.cs

@ -89,7 +89,7 @@ namespace Microsoft.Extensions.DependencyInjection
// or closed generics (e.g OpenIddictApplicationStore<OpenIddictApplication>).
if (type.IsGenericTypeDefinition)
{
if (type.GetGenericArguments().Length != 1)
if (type.GetGenericArguments() is not { Length: 1 })
{
throw new ArgumentException(SR.GetResourceString(SR.ID0232), nameof(type));
}
@ -145,7 +145,7 @@ namespace Microsoft.Extensions.DependencyInjection
// or closed generics (e.g OpenIddictAuthorizationStore<OpenIddictAuthorization>).
if (type.IsGenericTypeDefinition)
{
if (type.GetGenericArguments().Length != 1)
if (type.GetGenericArguments() is not { Length: 1 })
{
throw new ArgumentException(SR.GetResourceString(SR.ID0232), nameof(type));
}
@ -201,7 +201,7 @@ namespace Microsoft.Extensions.DependencyInjection
// or closed generics (e.g OpenIddictScopeStore<OpenIddictScope>).
if (type.IsGenericTypeDefinition)
{
if (type.GetGenericArguments().Length != 1)
if (type.GetGenericArguments() is not { Length: 1 })
{
throw new ArgumentException(SR.GetResourceString(SR.ID0232), nameof(type));
}
@ -257,7 +257,7 @@ namespace Microsoft.Extensions.DependencyInjection
// or closed generics (e.g OpenIddictTokenStore<OpenIddictToken>).
if (type.IsGenericTypeDefinition)
{
if (type.GetGenericArguments().Length != 1)
if (type.GetGenericArguments() is not { Length: 1 })
{
throw new ArgumentException(SR.GetResourceString(SR.ID0232), nameof(type));
}
@ -311,7 +311,7 @@ namespace Microsoft.Extensions.DependencyInjection
// or closed generics (e.g OpenIddictApplicationManager<OpenIddictApplication>).
if (type.IsGenericTypeDefinition)
{
if (type.GetGenericArguments().Length != 1)
if (type.GetGenericArguments() is not { Length: 1 })
{
throw new ArgumentException(SR.GetResourceString(SR.ID0232), nameof(type));
}
@ -405,7 +405,7 @@ namespace Microsoft.Extensions.DependencyInjection
// or closed generics (e.g OpenIddictAuthorizationManager<OpenIddictAuthorization>).
if (type.IsGenericTypeDefinition)
{
if (type.GetGenericArguments().Length != 1)
if (type.GetGenericArguments() is not { Length: 1 })
{
throw new ArgumentException(SR.GetResourceString(SR.ID0232), nameof(type));
}
@ -499,7 +499,7 @@ namespace Microsoft.Extensions.DependencyInjection
// or closed generics (e.g OpenIddictScopeManager<OpenIddictScope>).
if (type.IsGenericTypeDefinition)
{
if (type.GetGenericArguments().Length != 1)
if (type.GetGenericArguments() is not { Length: 1 })
{
throw new ArgumentException(SR.GetResourceString(SR.ID0232), nameof(type));
}
@ -593,7 +593,7 @@ namespace Microsoft.Extensions.DependencyInjection
// or closed generics (e.g OpenIddictTokenManager<OpenIddictToken>).
if (type.IsGenericTypeDefinition)
{
if (type.GetGenericArguments().Length != 1)
if (type.GetGenericArguments() is not { Length: 1 })
{
throw new ArgumentException(SR.GetResourceString(SR.ID0232), nameof(type));
}

2
src/OpenIddict.Server/OpenIddictServerEvents.Introspection.cs

@ -98,7 +98,7 @@ namespace OpenIddict.Server
/// <summary>
/// Gets or sets the security principal extracted from the introspected token.
/// </summary>
public ClaimsPrincipal? Principal { get; set; }
public ClaimsPrincipal Principal { get; set; } = default!;
/// <summary>
/// Gets the additional claims returned to the caller.

2
src/OpenIddict.Server/OpenIddictServerEvents.Revocation.cs

@ -98,7 +98,7 @@ namespace OpenIddict.Server
/// <summary>
/// Gets or sets the security principal extracted from the revoked token.
/// </summary>
public ClaimsPrincipal? Principal { get; set; }
public ClaimsPrincipal Principal { get; set; } = default!;
/// <summary>
/// Gets the authentication ticket.

2
src/OpenIddict.Server/OpenIddictServerEvents.Userinfo.cs

@ -93,7 +93,7 @@ namespace OpenIddict.Server
/// <summary>
/// Gets or sets the security principal extracted from the access token.
/// </summary>
public ClaimsPrincipal? Principal { get; set; }
public ClaimsPrincipal Principal { get; set; } = default!;
/// <summary>
/// Gets the additional claims returned to the client application.

2
src/OpenIddict.Server/OpenIddictServerHandlers.Introspection.cs

@ -870,6 +870,8 @@ namespace OpenIddict.Server
typeof(ValidateIntrospectionRequestContext).FullName!) ??
throw new InvalidOperationException(SR.GetResourceString(SR.ID0007));
Debug.Assert(notification.Principal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006));
context.Principal ??= notification.Principal;
return default;

2
src/OpenIddict.Server/OpenIddictServerHandlers.Revocation.cs

@ -813,6 +813,8 @@ namespace OpenIddict.Server
typeof(ValidateRevocationRequestContext).FullName!) ??
throw new InvalidOperationException(SR.GetResourceString(SR.ID0007));
Debug.Assert(notification.Principal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006));
context.Principal ??= notification.Principal;
return default;

2
src/OpenIddict.Server/OpenIddictServerHandlers.Userinfo.cs

@ -438,6 +438,8 @@ namespace OpenIddict.Server
typeof(ValidateUserinfoRequestContext).FullName!) ??
throw new InvalidOperationException(SR.GetResourceString(SR.ID0007));
Debug.Assert(notification.Principal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006));
context.Principal ??= notification.Principal;
return default;

6
src/OpenIddict.Server/OpenIddictServerHandlers.cs

@ -1030,7 +1030,7 @@ namespace OpenIddict.Server
typeof(ProcessAuthenticationContext).FullName!) ??
throw new InvalidOperationException(SR.GetResourceString(SR.ID0007));
Debug.Assert(notification.UserCodePrincipal is not null, SR.GetResourceString(SR.ID4006));
Debug.Assert(notification.UserCodePrincipal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006));
// Extract the device code identifier from the user code principal.
var identifier = notification.UserCodePrincipal.GetClaim(Claims.Private.DeviceCodeId);
@ -1089,7 +1089,7 @@ namespace OpenIddict.Server
typeof(ProcessAuthenticationContext).FullName!) ??
throw new InvalidOperationException(SR.GetResourceString(SR.ID0007));
Debug.Assert(notification.UserCodePrincipal is not null, SR.GetResourceString(SR.ID4006));
Debug.Assert(notification.UserCodePrincipal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006));
// Extract the device code identifier from the authentication principal.
var identifier = notification.UserCodePrincipal.GetTokenId();
@ -1916,7 +1916,7 @@ namespace OpenIddict.Server
typeof(ProcessAuthenticationContext).FullName!) ??
throw new InvalidOperationException(SR.GetResourceString(SR.ID0007));
Debug.Assert(notification.RefreshTokenPrincipal is not null, SR.GetResourceString(SR.ID4006));
Debug.Assert(notification.RefreshTokenPrincipal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006));
principal.SetExpirationDate(notification.RefreshTokenPrincipal.GetExpirationDate());
}

Loading…
Cancel
Save