|
|
@ -7,7 +7,6 @@ |
|
|
using System.Collections.Immutable; |
|
|
using System.Collections.Immutable; |
|
|
using System.ComponentModel; |
|
|
using System.ComponentModel; |
|
|
using System.Diagnostics; |
|
|
using System.Diagnostics; |
|
|
using System.Security.Claims; |
|
|
|
|
|
using System.Text; |
|
|
using System.Text; |
|
|
using System.Text.Encodings.Web; |
|
|
using System.Text.Encodings.Web; |
|
|
using System.Text.Json; |
|
|
using System.Text.Json; |
|
|
@ -38,18 +37,18 @@ public static partial class OpenIddictServerAspNetCoreHandlers |
|
|
/* |
|
|
/* |
|
|
* Challenge processing: |
|
|
* Challenge processing: |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
ResolveHostChallengeProperties.Descriptor, |
|
|
AttachHostChallengeError.Descriptor, |
|
|
AttachHostChallengeError.Descriptor, |
|
|
ResolveHostChallengeParameters.Descriptor, |
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
/* |
|
|
* Sign-in processing: |
|
|
* Sign-in processing: |
|
|
*/ |
|
|
*/ |
|
|
ResolveHostSignInParameters.Descriptor, |
|
|
ResolveHostSignInProperties.Descriptor, |
|
|
|
|
|
|
|
|
/* |
|
|
/* |
|
|
* Sign-out processing: |
|
|
* Sign-out processing: |
|
|
*/ |
|
|
*/ |
|
|
ResolveHostSignOutParameters.Descriptor) |
|
|
ResolveHostSignOutProperties.Descriptor) |
|
|
.AddRange(Authentication.DefaultHandlers) |
|
|
.AddRange(Authentication.DefaultHandlers) |
|
|
.AddRange(Device.DefaultHandlers) |
|
|
.AddRange(Device.DefaultHandlers) |
|
|
.AddRange(Discovery.DefaultHandlers) |
|
|
.AddRange(Discovery.DefaultHandlers) |
|
|
@ -279,10 +278,11 @@ public static partial class OpenIddictServerAspNetCoreHandlers |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Contains the logic responsible for attaching the error details using the ASP.NET Core authentication properties.
|
|
|
/// Contains the logic responsible for resolving the context-specific properties and parameters stored in the
|
|
|
|
|
|
/// ASP.NET Core authentication properties specified by the application that triggered the challenge operation.
|
|
|
/// Note: this handler is not used when the OpenID Connect request is not initially handled by ASP.NET Core.
|
|
|
/// Note: this handler is not used when the OpenID Connect request is not initially handled by ASP.NET Core.
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
public class AttachHostChallengeError : IOpenIddictServerHandler<ProcessChallengeContext> |
|
|
public class ResolveHostChallengeProperties : IOpenIddictServerHandler<ProcessChallengeContext> |
|
|
{ |
|
|
{ |
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Gets the default descriptor definition assigned to this handler.
|
|
|
/// Gets the default descriptor definition assigned to this handler.
|
|
|
@ -290,8 +290,8 @@ public static partial class OpenIddictServerAspNetCoreHandlers |
|
|
public static OpenIddictServerHandlerDescriptor Descriptor { get; } |
|
|
public static OpenIddictServerHandlerDescriptor Descriptor { get; } |
|
|
= OpenIddictServerHandlerDescriptor.CreateBuilder<ProcessChallengeContext>() |
|
|
= OpenIddictServerHandlerDescriptor.CreateBuilder<ProcessChallengeContext>() |
|
|
.AddFilter<RequireHttpRequest>() |
|
|
.AddFilter<RequireHttpRequest>() |
|
|
.UseSingletonHandler<AttachHostChallengeError>() |
|
|
.UseSingletonHandler<ResolveHostChallengeProperties>() |
|
|
.SetOrder(AttachDefaultChallengeError.Descriptor.Order - 500) |
|
|
.SetOrder(ValidateChallengeDemand.Descriptor.Order - 500) |
|
|
.SetType(OpenIddictServerHandlerType.BuiltIn) |
|
|
.SetType(OpenIddictServerHandlerType.BuiltIn) |
|
|
.Build(); |
|
|
.Build(); |
|
|
|
|
|
|
|
|
@ -304,12 +304,34 @@ public static partial class OpenIddictServerAspNetCoreHandlers |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var properties = context.Transaction.GetProperty<AuthenticationProperties>(typeof(AuthenticationProperties).FullName!); |
|
|
var properties = context.Transaction.GetProperty<AuthenticationProperties>(typeof(AuthenticationProperties).FullName!); |
|
|
if (properties is not null) |
|
|
if (properties is { Items.Count: > 0 }) |
|
|
{ |
|
|
{ |
|
|
context.Response.Error = properties.GetString(Properties.Error); |
|
|
foreach (var property in properties.Items) |
|
|
context.Response.ErrorDescription = properties.GetString(Properties.ErrorDescription); |
|
|
{ |
|
|
context.Response.ErrorUri = properties.GetString(Properties.ErrorUri); |
|
|
context.Properties[property.Key] = property.Value; |
|
|
context.Response.Scope = properties.GetString(Properties.Scope); |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (properties is { Parameters.Count: > 0 }) |
|
|
|
|
|
{ |
|
|
|
|
|
foreach (var parameter in properties.Parameters) |
|
|
|
|
|
{ |
|
|
|
|
|
context.Parameters[parameter.Key] = parameter.Value switch |
|
|
|
|
|
{ |
|
|
|
|
|
OpenIddictParameter value => value, |
|
|
|
|
|
JsonElement value => new OpenIddictParameter(value), |
|
|
|
|
|
bool value => new OpenIddictParameter(value), |
|
|
|
|
|
int value => new OpenIddictParameter(value), |
|
|
|
|
|
long value => new OpenIddictParameter(value), |
|
|
|
|
|
string value => new OpenIddictParameter(value), |
|
|
|
|
|
string[] value => new OpenIddictParameter(value), |
|
|
|
|
|
|
|
|
|
|
|
#if SUPPORTS_JSON_NODES
|
|
|
|
|
|
JsonNode value => new OpenIddictParameter(value), |
|
|
|
|
|
#endif
|
|
|
|
|
|
_ => throw new InvalidOperationException(SR.GetResourceString(SR.ID0115)) |
|
|
|
|
|
}; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return default; |
|
|
return default; |
|
|
@ -317,11 +339,10 @@ public static partial class OpenIddictServerAspNetCoreHandlers |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Contains the logic responsible for resolving the additional challenge parameters stored in the ASP.NET
|
|
|
/// Contains the logic responsible for attaching the error details using the ASP.NET Core authentication properties.
|
|
|
/// Core authentication properties specified by the application that triggered the sign-in operation.
|
|
|
|
|
|
/// Note: this handler is not used when the OpenID Connect request is not initially handled by ASP.NET Core.
|
|
|
/// Note: this handler is not used when the OpenID Connect request is not initially handled by ASP.NET Core.
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
public class ResolveHostChallengeParameters : IOpenIddictServerHandler<ProcessChallengeContext> |
|
|
public class AttachHostChallengeError : IOpenIddictServerHandler<ProcessChallengeContext> |
|
|
{ |
|
|
{ |
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Gets the default descriptor definition assigned to this handler.
|
|
|
/// Gets the default descriptor definition assigned to this handler.
|
|
|
@ -329,8 +350,8 @@ public static partial class OpenIddictServerAspNetCoreHandlers |
|
|
public static OpenIddictServerHandlerDescriptor Descriptor { get; } |
|
|
public static OpenIddictServerHandlerDescriptor Descriptor { get; } |
|
|
= OpenIddictServerHandlerDescriptor.CreateBuilder<ProcessChallengeContext>() |
|
|
= OpenIddictServerHandlerDescriptor.CreateBuilder<ProcessChallengeContext>() |
|
|
.AddFilter<RequireHttpRequest>() |
|
|
.AddFilter<RequireHttpRequest>() |
|
|
.UseSingletonHandler<ResolveHostChallengeParameters>() |
|
|
.UseSingletonHandler<AttachHostChallengeError>() |
|
|
.SetOrder(AttachCustomChallengeParameters.Descriptor.Order - 500) |
|
|
.SetOrder(AttachDefaultChallengeError.Descriptor.Order - 500) |
|
|
.SetType(OpenIddictServerHandlerType.BuiltIn) |
|
|
.SetType(OpenIddictServerHandlerType.BuiltIn) |
|
|
.Build(); |
|
|
.Build(); |
|
|
|
|
|
|
|
|
@ -343,28 +364,12 @@ public static partial class OpenIddictServerAspNetCoreHandlers |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var properties = context.Transaction.GetProperty<AuthenticationProperties>(typeof(AuthenticationProperties).FullName!); |
|
|
var properties = context.Transaction.GetProperty<AuthenticationProperties>(typeof(AuthenticationProperties).FullName!); |
|
|
if (properties is null) |
|
|
if (properties is not null) |
|
|
{ |
|
|
|
|
|
return default; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
foreach (var parameter in properties.Parameters) |
|
|
|
|
|
{ |
|
|
{ |
|
|
context.Parameters[parameter.Key] = parameter.Value switch |
|
|
context.Response.Error = properties.GetString(Properties.Error); |
|
|
{ |
|
|
context.Response.ErrorDescription = properties.GetString(Properties.ErrorDescription); |
|
|
OpenIddictParameter value => value, |
|
|
context.Response.ErrorUri = properties.GetString(Properties.ErrorUri); |
|
|
JsonElement value => new OpenIddictParameter(value), |
|
|
context.Response.Scope = properties.GetString(Properties.Scope); |
|
|
bool value => new OpenIddictParameter(value), |
|
|
|
|
|
int value => new OpenIddictParameter(value), |
|
|
|
|
|
long value => new OpenIddictParameter(value), |
|
|
|
|
|
string value => new OpenIddictParameter(value), |
|
|
|
|
|
string[] value => new OpenIddictParameter(value), |
|
|
|
|
|
|
|
|
|
|
|
#if SUPPORTS_JSON_NODES
|
|
|
|
|
|
JsonNode value => new OpenIddictParameter(value), |
|
|
|
|
|
#endif
|
|
|
|
|
|
_ => throw new InvalidOperationException(SR.GetResourceString(SR.ID0115)) |
|
|
|
|
|
}; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return default; |
|
|
return default; |
|
|
@ -372,11 +377,11 @@ public static partial class OpenIddictServerAspNetCoreHandlers |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Contains the logic responsible for resolving the additional sign-in parameters stored in the ASP.NET
|
|
|
/// Contains the logic responsible for resolving the context-specific properties and parameters stored in the
|
|
|
/// Core authentication properties specified by the application that triggered the sign-in operation.
|
|
|
/// ASP.NET Core authentication properties specified by the application that triggered the sign-in operation.
|
|
|
/// Note: this handler is not used when the OpenID Connect request is not initially handled by ASP.NET Core.
|
|
|
/// Note: this handler is not used when the OpenID Connect request is not initially handled by ASP.NET Core.
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
public class ResolveHostSignInParameters : IOpenIddictServerHandler<ProcessSignInContext> |
|
|
public class ResolveHostSignInProperties : IOpenIddictServerHandler<ProcessSignInContext> |
|
|
{ |
|
|
{ |
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Gets the default descriptor definition assigned to this handler.
|
|
|
/// Gets the default descriptor definition assigned to this handler.
|
|
|
@ -384,8 +389,8 @@ public static partial class OpenIddictServerAspNetCoreHandlers |
|
|
public static OpenIddictServerHandlerDescriptor Descriptor { get; } |
|
|
public static OpenIddictServerHandlerDescriptor Descriptor { get; } |
|
|
= OpenIddictServerHandlerDescriptor.CreateBuilder<ProcessSignInContext>() |
|
|
= OpenIddictServerHandlerDescriptor.CreateBuilder<ProcessSignInContext>() |
|
|
.AddFilter<RequireHttpRequest>() |
|
|
.AddFilter<RequireHttpRequest>() |
|
|
.UseSingletonHandler<ResolveHostSignInParameters>() |
|
|
.UseSingletonHandler<ResolveHostSignInProperties>() |
|
|
.SetOrder(AttachCustomSignInParameters.Descriptor.Order - 500) |
|
|
.SetOrder(ValidateSignInDemand.Descriptor.Order - 500) |
|
|
.SetType(OpenIddictServerHandlerType.BuiltIn) |
|
|
.SetType(OpenIddictServerHandlerType.BuiltIn) |
|
|
.Build(); |
|
|
.Build(); |
|
|
|
|
|
|
|
|
@ -397,37 +402,35 @@ public static partial class OpenIddictServerAspNetCoreHandlers |
|
|
throw new ArgumentNullException(nameof(context)); |
|
|
throw new ArgumentNullException(nameof(context)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
Debug.Assert(context.Principal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006)); |
|
|
|
|
|
|
|
|
|
|
|
var properties = context.Transaction.GetProperty<AuthenticationProperties>(typeof(AuthenticationProperties).FullName!); |
|
|
var properties = context.Transaction.GetProperty<AuthenticationProperties>(typeof(AuthenticationProperties).FullName!); |
|
|
if (properties is null) |
|
|
if (properties is { Items.Count: > 0 }) |
|
|
{ |
|
|
{ |
|
|
return default; |
|
|
foreach (var property in properties.Items) |
|
|
} |
|
|
{ |
|
|
|
|
|
context.Properties[property.Key] = property.Value; |
|
|
// Preserve the host properties in the principal.
|
|
|
} |
|
|
if (properties.Items.Count is not 0) |
|
|
|
|
|
{ |
|
|
|
|
|
context.Principal.SetClaim(Claims.Private.HostProperties, properties.Items); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
foreach (var parameter in properties.Parameters) |
|
|
if (properties is { Parameters.Count: > 0 }) |
|
|
{ |
|
|
{ |
|
|
context.Parameters[parameter.Key] = parameter.Value switch |
|
|
foreach (var parameter in properties.Parameters) |
|
|
{ |
|
|
{ |
|
|
OpenIddictParameter value => value, |
|
|
context.Parameters[parameter.Key] = parameter.Value switch |
|
|
JsonElement value => new OpenIddictParameter(value), |
|
|
{ |
|
|
bool value => new OpenIddictParameter(value), |
|
|
OpenIddictParameter value => value, |
|
|
int value => new OpenIddictParameter(value), |
|
|
JsonElement value => new OpenIddictParameter(value), |
|
|
long value => new OpenIddictParameter(value), |
|
|
bool value => new OpenIddictParameter(value), |
|
|
string value => new OpenIddictParameter(value), |
|
|
int value => new OpenIddictParameter(value), |
|
|
string[] value => new OpenIddictParameter(value), |
|
|
long value => new OpenIddictParameter(value), |
|
|
|
|
|
string value => new OpenIddictParameter(value), |
|
|
|
|
|
string[] value => new OpenIddictParameter(value), |
|
|
|
|
|
|
|
|
#if SUPPORTS_JSON_NODES
|
|
|
#if SUPPORTS_JSON_NODES
|
|
|
JsonNode value => new OpenIddictParameter(value), |
|
|
JsonNode value => new OpenIddictParameter(value), |
|
|
#endif
|
|
|
#endif
|
|
|
_ => throw new InvalidOperationException(SR.GetResourceString(SR.ID0115)) |
|
|
_ => throw new InvalidOperationException(SR.GetResourceString(SR.ID0115)) |
|
|
}; |
|
|
}; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return default; |
|
|
return default; |
|
|
@ -435,11 +438,11 @@ public static partial class OpenIddictServerAspNetCoreHandlers |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Contains the logic responsible for resolving the additional sign-out parameters stored in the ASP.NET
|
|
|
/// Contains the logic responsible for resolving the context-specific properties and parameters stored in the
|
|
|
/// Core authentication properties specified by the application that triggered the sign-out operation.
|
|
|
/// ASP.NET Core authentication properties specified by the application that triggered the sign-out operation.
|
|
|
/// Note: this handler is not used when the OpenID Connect request is not initially handled by ASP.NET Core.
|
|
|
/// Note: this handler is not used when the OpenID Connect request is not initially handled by ASP.NET Core.
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
public class ResolveHostSignOutParameters : IOpenIddictServerHandler<ProcessSignOutContext> |
|
|
public class ResolveHostSignOutProperties : IOpenIddictServerHandler<ProcessSignOutContext> |
|
|
{ |
|
|
{ |
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Gets the default descriptor definition assigned to this handler.
|
|
|
/// Gets the default descriptor definition assigned to this handler.
|
|
|
@ -447,8 +450,8 @@ public static partial class OpenIddictServerAspNetCoreHandlers |
|
|
public static OpenIddictServerHandlerDescriptor Descriptor { get; } |
|
|
public static OpenIddictServerHandlerDescriptor Descriptor { get; } |
|
|
= OpenIddictServerHandlerDescriptor.CreateBuilder<ProcessSignOutContext>() |
|
|
= OpenIddictServerHandlerDescriptor.CreateBuilder<ProcessSignOutContext>() |
|
|
.AddFilter<RequireHttpRequest>() |
|
|
.AddFilter<RequireHttpRequest>() |
|
|
.UseSingletonHandler<ResolveHostSignOutParameters>() |
|
|
.UseSingletonHandler<ResolveHostSignOutProperties>() |
|
|
.SetOrder(AttachCustomSignOutParameters.Descriptor.Order - 500) |
|
|
.SetOrder(ValidateSignOutDemand.Descriptor.Order - 500) |
|
|
.SetType(OpenIddictServerHandlerType.BuiltIn) |
|
|
.SetType(OpenIddictServerHandlerType.BuiltIn) |
|
|
.Build(); |
|
|
.Build(); |
|
|
|
|
|
|
|
|
@ -461,28 +464,34 @@ public static partial class OpenIddictServerAspNetCoreHandlers |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var properties = context.Transaction.GetProperty<AuthenticationProperties>(typeof(AuthenticationProperties).FullName!); |
|
|
var properties = context.Transaction.GetProperty<AuthenticationProperties>(typeof(AuthenticationProperties).FullName!); |
|
|
if (properties is null) |
|
|
if (properties is { Items.Count: > 0 }) |
|
|
{ |
|
|
{ |
|
|
return default; |
|
|
foreach (var property in properties.Items) |
|
|
|
|
|
{ |
|
|
|
|
|
context.Properties[property.Key] = property.Value; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
foreach (var parameter in properties.Parameters) |
|
|
if (properties is { Parameters.Count: > 0 }) |
|
|
{ |
|
|
{ |
|
|
context.Parameters[parameter.Key] = parameter.Value switch |
|
|
foreach (var parameter in properties.Parameters) |
|
|
{ |
|
|
{ |
|
|
OpenIddictParameter value => value, |
|
|
context.Parameters[parameter.Key] = parameter.Value switch |
|
|
JsonElement value => new OpenIddictParameter(value), |
|
|
{ |
|
|
bool value => new OpenIddictParameter(value), |
|
|
OpenIddictParameter value => value, |
|
|
int value => new OpenIddictParameter(value), |
|
|
JsonElement value => new OpenIddictParameter(value), |
|
|
long value => new OpenIddictParameter(value), |
|
|
bool value => new OpenIddictParameter(value), |
|
|
string value => new OpenIddictParameter(value), |
|
|
int value => new OpenIddictParameter(value), |
|
|
string[] value => new OpenIddictParameter(value), |
|
|
long value => new OpenIddictParameter(value), |
|
|
|
|
|
string value => new OpenIddictParameter(value), |
|
|
|
|
|
string[] value => new OpenIddictParameter(value), |
|
|
|
|
|
|
|
|
#if SUPPORTS_JSON_NODES
|
|
|
#if SUPPORTS_JSON_NODES
|
|
|
JsonNode value => new OpenIddictParameter(value), |
|
|
JsonNode value => new OpenIddictParameter(value), |
|
|
#endif
|
|
|
#endif
|
|
|
_ => throw new InvalidOperationException(SR.GetResourceString(SR.ID0115)) |
|
|
_ => throw new InvalidOperationException(SR.GetResourceString(SR.ID0115)) |
|
|
}; |
|
|
}; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return default; |
|
|
return default; |
|
|
|