|
|
@ -9,7 +9,6 @@ using System.ComponentModel; |
|
|
using System.Diagnostics; |
|
|
using System.Diagnostics; |
|
|
using System.Net; |
|
|
using System.Net; |
|
|
using System.Runtime.CompilerServices; |
|
|
using System.Runtime.CompilerServices; |
|
|
using System.Runtime.Versioning; |
|
|
|
|
|
using System.Security.Claims; |
|
|
using System.Security.Claims; |
|
|
using System.Text; |
|
|
using System.Text; |
|
|
using Microsoft.Extensions.Hosting; |
|
|
using Microsoft.Extensions.Hosting; |
|
|
@ -24,18 +23,6 @@ using static OpenIddict.Client.SystemIntegration.OpenIddictClientSystemIntegrati |
|
|
using IHostApplicationLifetime = Microsoft.Extensions.Hosting.IApplicationLifetime; |
|
|
using IHostApplicationLifetime = Microsoft.Extensions.Hosting.IApplicationLifetime; |
|
|
#endif
|
|
|
#endif
|
|
|
|
|
|
|
|
|
#if SUPPORTS_ANDROID
|
|
|
|
|
|
using NativeUri = Android.Net.Uri; |
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#if SUPPORTS_FOUNDATION
|
|
|
|
|
|
using Foundation; |
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#if SUPPORTS_WINDOWS_RUNTIME
|
|
|
|
|
|
using Windows.Security.Authentication.Web; |
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
namespace OpenIddict.Client.SystemIntegration; |
|
|
namespace OpenIddict.Client.SystemIntegration; |
|
|
|
|
|
|
|
|
[EditorBrowsable(EditorBrowsableState.Never)] |
|
|
[EditorBrowsable(EditorBrowsableState.Never)] |
|
|
@ -47,9 +34,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers |
|
|
*/ |
|
|
*/ |
|
|
ResolveRequestUriFromHttpListenerRequest.Descriptor, |
|
|
ResolveRequestUriFromHttpListenerRequest.Descriptor, |
|
|
ResolveRequestUriFromProtocolActivation.Descriptor, |
|
|
ResolveRequestUriFromProtocolActivation.Descriptor, |
|
|
ResolveRequestUriFromASWebAuthenticationCallbackUrl.Descriptor, |
|
|
ResolveRequestUriFromPlatformCallback.Descriptor, |
|
|
ResolveRequestUriFromCustomTabsIntentData.Descriptor, |
|
|
|
|
|
ResolveRequestUriFromWebAuthenticationResult.Descriptor, |
|
|
|
|
|
InferEndpointTypeFromDynamicAddress.Descriptor, |
|
|
InferEndpointTypeFromDynamicAddress.Descriptor, |
|
|
RejectUnknownHttpRequests.Descriptor, |
|
|
RejectUnknownHttpRequests.Descriptor, |
|
|
|
|
|
|
|
|
@ -215,26 +200,23 @@ public static partial class OpenIddictClientSystemIntegrationHandlers |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Contains the logic responsible for resolving the request URI from the AS web authentication session callback URL.
|
|
|
/// Contains the logic responsible for resolving the request URI from the platform callback details.
|
|
|
/// Note: this handler is not used when the OpenID Connect request is not an AS web authentication session callback URL.
|
|
|
/// Note: this handler is not used when the OpenID Connect request is not a platform callback.
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
public sealed class ResolveRequestUriFromASWebAuthenticationCallbackUrl : IOpenIddictClientHandler<ProcessRequestContext> |
|
|
public sealed class ResolveRequestUriFromPlatformCallback : IOpenIddictClientHandler<ProcessRequestContext> |
|
|
{ |
|
|
{ |
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Gets the default descriptor definition assigned to this handler.
|
|
|
/// Gets the default descriptor definition assigned to this handler.
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
public static OpenIddictClientHandlerDescriptor Descriptor { get; } |
|
|
public static OpenIddictClientHandlerDescriptor Descriptor { get; } |
|
|
= OpenIddictClientHandlerDescriptor.CreateBuilder<ProcessRequestContext>() |
|
|
= OpenIddictClientHandlerDescriptor.CreateBuilder<ProcessRequestContext>() |
|
|
.AddFilter<RequireASWebAuthenticationCallbackUrl>() |
|
|
.AddFilter<RequirePlatformCallback>() |
|
|
.UseSingletonHandler<ResolveRequestUriFromASWebAuthenticationCallbackUrl>() |
|
|
.UseSingletonHandler<ResolveRequestUriFromPlatformCallback>() |
|
|
.SetOrder(ResolveRequestUriFromProtocolActivation.Descriptor.Order + 1_000) |
|
|
.SetOrder(ResolveRequestUriFromProtocolActivation.Descriptor.Order + 1_000) |
|
|
.SetType(OpenIddictClientHandlerType.BuiltIn) |
|
|
.SetType(OpenIddictClientHandlerType.BuiltIn) |
|
|
.Build(); |
|
|
.Build(); |
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
/// <inheritdoc/>
|
|
|
[SupportedOSPlatform("ios12.0")] |
|
|
|
|
|
[SupportedOSPlatform("maccatalyst13.1")] |
|
|
|
|
|
[SupportedOSPlatform("macos10.15")] |
|
|
|
|
|
public ValueTask HandleAsync(ProcessRequestContext context) |
|
|
public ValueTask HandleAsync(ProcessRequestContext context) |
|
|
{ |
|
|
{ |
|
|
if (context is null) |
|
|
if (context is null) |
|
|
@ -242,10 +224,9 @@ public static partial class OpenIddictClientSystemIntegrationHandlers |
|
|
throw new ArgumentNullException(nameof(context)); |
|
|
throw new ArgumentNullException(nameof(context)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
#if SUPPORTS_AUTHENTICATION_SERVICES && SUPPORTS_FOUNDATION
|
|
|
(context.BaseUri, context.RequestUri) = context.Transaction.GetPlatformCallback() switch |
|
|
(context.BaseUri, context.RequestUri) = context.Transaction.GetASWebAuthenticationCallbackUrl() switch |
|
|
|
|
|
{ |
|
|
{ |
|
|
NSUrl url when Uri.TryCreate(url.AbsoluteString, UriKind.Absolute, out Uri? uri) => ( |
|
|
{ CallbackUri: Uri uri } => ( |
|
|
BaseUri: new UriBuilder(uri) { Path = null, Query = null, Fragment = null }.Uri, |
|
|
BaseUri: new UriBuilder(uri) { Path = null, Query = null, Fragment = null }.Uri, |
|
|
RequestUri: uri), |
|
|
RequestUri: uri), |
|
|
|
|
|
|
|
|
@ -253,52 +234,6 @@ public static partial class OpenIddictClientSystemIntegrationHandlers |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
return default; |
|
|
return default; |
|
|
#else
|
|
|
|
|
|
throw new PlatformNotSupportedException(SR.GetResourceString(SR.ID0446)); |
|
|
|
|
|
#endif
|
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Contains the logic responsible for resolving the request URI from the custom tabs intent data.
|
|
|
|
|
|
/// Note: this handler is not used when the OpenID Connect request is not an custom tabs intent callback.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public sealed class ResolveRequestUriFromCustomTabsIntentData : IOpenIddictClientHandler<ProcessRequestContext> |
|
|
|
|
|
{ |
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets the default descriptor definition assigned to this handler.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public static OpenIddictClientHandlerDescriptor Descriptor { get; } |
|
|
|
|
|
= OpenIddictClientHandlerDescriptor.CreateBuilder<ProcessRequestContext>() |
|
|
|
|
|
.AddFilter<RequireCustomTabsIntentData>() |
|
|
|
|
|
.UseSingletonHandler<ResolveRequestUriFromCustomTabsIntentData>() |
|
|
|
|
|
.SetOrder(ResolveRequestUriFromASWebAuthenticationCallbackUrl.Descriptor.Order + 1_000) |
|
|
|
|
|
.SetType(OpenIddictClientHandlerType.BuiltIn) |
|
|
|
|
|
.Build(); |
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
|
[SupportedOSPlatform("android21.0")] |
|
|
|
|
|
public ValueTask HandleAsync(ProcessRequestContext context) |
|
|
|
|
|
{ |
|
|
|
|
|
if (context is null) |
|
|
|
|
|
{ |
|
|
|
|
|
throw new ArgumentNullException(nameof(context)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#if SUPPORTS_ANDROID
|
|
|
|
|
|
(context.BaseUri, context.RequestUri) = context.Transaction.GetCustomTabsIntentData() switch |
|
|
|
|
|
{ |
|
|
|
|
|
NativeUri url when Uri.TryCreate(url.ToString(), UriKind.Absolute, out Uri? uri) => ( |
|
|
|
|
|
BaseUri: new UriBuilder(uri) { Path = null, Query = null, Fragment = null }.Uri, |
|
|
|
|
|
RequestUri: uri), |
|
|
|
|
|
|
|
|
|
|
|
_ => throw new InvalidOperationException(SR.GetResourceString(SR.ID0393)) |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
return default; |
|
|
|
|
|
#else
|
|
|
|
|
|
throw new PlatformNotSupportedException(SR.GetResourceString(SR.ID0452)); |
|
|
|
|
|
#endif
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -306,6 +241,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers |
|
|
/// Contains the logic responsible for resolving the request URI from the web authentication result.
|
|
|
/// Contains the logic responsible for resolving the request URI from the web authentication result.
|
|
|
/// Note: this handler is not used when the OpenID Connect request is not a web authentication result.
|
|
|
/// Note: this handler is not used when the OpenID Connect request is not a web authentication result.
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
|
|
|
[Obsolete("This event handler is obsolete and will be removed in a future version.")] |
|
|
public sealed class ResolveRequestUriFromWebAuthenticationResult : IOpenIddictClientHandler<ProcessRequestContext> |
|
|
public sealed class ResolveRequestUriFromWebAuthenticationResult : IOpenIddictClientHandler<ProcessRequestContext> |
|
|
{ |
|
|
{ |
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
@ -315,35 +251,13 @@ public static partial class OpenIddictClientSystemIntegrationHandlers |
|
|
= OpenIddictClientHandlerDescriptor.CreateBuilder<ProcessRequestContext>() |
|
|
= OpenIddictClientHandlerDescriptor.CreateBuilder<ProcessRequestContext>() |
|
|
.AddFilter<RequireWebAuthenticationResult>() |
|
|
.AddFilter<RequireWebAuthenticationResult>() |
|
|
.UseSingletonHandler<ResolveRequestUriFromWebAuthenticationResult>() |
|
|
.UseSingletonHandler<ResolveRequestUriFromWebAuthenticationResult>() |
|
|
.SetOrder(ResolveRequestUriFromCustomTabsIntentData.Descriptor.Order + 1_000) |
|
|
.SetOrder(ResolveRequestUriFromPlatformCallback.Descriptor.Order + 1_000) |
|
|
.SetType(OpenIddictClientHandlerType.BuiltIn) |
|
|
.SetType(OpenIddictClientHandlerType.BuiltIn) |
|
|
.Build(); |
|
|
.Build(); |
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
/// <inheritdoc/>
|
|
|
[SupportedOSPlatform("windows10.0.17763")] |
|
|
|
|
|
public ValueTask HandleAsync(ProcessRequestContext context) |
|
|
public ValueTask HandleAsync(ProcessRequestContext context) |
|
|
{ |
|
|
=> throw new NotSupportedException(SR.GetResourceString(SR.ID0403)); |
|
|
if (context is null) |
|
|
|
|
|
{ |
|
|
|
|
|
throw new ArgumentNullException(nameof(context)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#if SUPPORTS_WINDOWS_RUNTIME
|
|
|
|
|
|
(context.BaseUri, context.RequestUri) = context.Transaction.GetWebAuthenticationResult() switch |
|
|
|
|
|
{ |
|
|
|
|
|
{ ResponseStatus: WebAuthenticationStatus.Success, ResponseData: string data } when |
|
|
|
|
|
Uri.TryCreate(data, UriKind.Absolute, out Uri? uri) => ( |
|
|
|
|
|
BaseUri: new UriBuilder(uri) { Path = null, Query = null, Fragment = null }.Uri, |
|
|
|
|
|
RequestUri: uri), |
|
|
|
|
|
|
|
|
|
|
|
_ => throw new InvalidOperationException(SR.GetResourceString(SR.ID0393)) |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
return default; |
|
|
|
|
|
#else
|
|
|
|
|
|
throw new PlatformNotSupportedException(SR.GetResourceString(SR.ID0392)); |
|
|
|
|
|
#endif
|
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
@ -671,26 +585,23 @@ public static partial class OpenIddictClientSystemIntegrationHandlers |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Contains the logic responsible for extracting OpenID Connect requests from the callback URL of an AS session.
|
|
|
/// Contains the logic responsible for extracting OpenID Connect requests from the URI of a platform callback.
|
|
|
/// Note: this handler is not used when the OpenID Connect request is not an AS web authentication session callback.
|
|
|
/// Note: this handler is not used when the OpenID Connect request is not a platform callback.
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
public sealed class ExtractASWebAuthenticationCallbackUrlData<TContext> : IOpenIddictClientHandler<TContext> where TContext : BaseValidatingContext |
|
|
public sealed class ExtractPlatformCallbackParameters<TContext> : IOpenIddictClientHandler<TContext> where TContext : BaseValidatingContext |
|
|
{ |
|
|
{ |
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Gets the default descriptor definition assigned to this handler.
|
|
|
/// Gets the default descriptor definition assigned to this handler.
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
public static OpenIddictClientHandlerDescriptor Descriptor { get; } |
|
|
public static OpenIddictClientHandlerDescriptor Descriptor { get; } |
|
|
= OpenIddictClientHandlerDescriptor.CreateBuilder<TContext>() |
|
|
= OpenIddictClientHandlerDescriptor.CreateBuilder<TContext>() |
|
|
.AddFilter<RequireASWebAuthenticationCallbackUrl>() |
|
|
.AddFilter<RequirePlatformCallback>() |
|
|
.UseSingletonHandler<ExtractASWebAuthenticationCallbackUrlData<TContext>>() |
|
|
.UseSingletonHandler<ExtractPlatformCallbackParameters<TContext>>() |
|
|
.SetOrder(ExtractProtocolActivationParameters<TContext>.Descriptor.Order + 1_000) |
|
|
.SetOrder(ExtractProtocolActivationParameters<TContext>.Descriptor.Order + 1_000) |
|
|
.SetType(OpenIddictClientHandlerType.BuiltIn) |
|
|
.SetType(OpenIddictClientHandlerType.BuiltIn) |
|
|
.Build(); |
|
|
.Build(); |
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
/// <inheritdoc/>
|
|
|
[SupportedOSPlatform("ios12.0")] |
|
|
|
|
|
[SupportedOSPlatform("maccatalyst13.1")] |
|
|
|
|
|
[SupportedOSPlatform("macos10.15")] |
|
|
|
|
|
public ValueTask HandleAsync(TContext context) |
|
|
public ValueTask HandleAsync(TContext context) |
|
|
{ |
|
|
{ |
|
|
if (context is null) |
|
|
if (context is null) |
|
|
@ -698,105 +609,14 @@ public static partial class OpenIddictClientSystemIntegrationHandlers |
|
|
throw new ArgumentNullException(nameof(context)); |
|
|
throw new ArgumentNullException(nameof(context)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
#if SUPPORTS_AUTHENTICATION_SERVICES && SUPPORTS_FOUNDATION
|
|
|
if (context.Transaction.GetPlatformCallback() is not OpenIddictClientSystemIntegrationPlatformCallback callback) |
|
|
if (context.Transaction.GetASWebAuthenticationCallbackUrl() |
|
|
|
|
|
is not NSUrl url || !Uri.TryCreate(url.AbsoluteString, UriKind.Absolute, out Uri? uri)) |
|
|
|
|
|
{ |
|
|
{ |
|
|
throw new InvalidOperationException(SR.GetResourceString(SR.ID0393)); |
|
|
throw new InvalidOperationException(SR.GetResourceString(SR.ID0393)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var parameters = new Dictionary<string, StringValues>(StringComparer.Ordinal); |
|
|
context.Transaction.Request = new OpenIddictRequest(callback.Parameters); |
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(uri.Query)) |
|
|
|
|
|
{ |
|
|
|
|
|
foreach (var parameter in OpenIddictHelpers.ParseQuery(uri.Query)) |
|
|
|
|
|
{ |
|
|
|
|
|
parameters[parameter.Key] = parameter.Value; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Note: the fragment is always processed after the query string to ensure that
|
|
|
|
|
|
// parameters extracted from the fragment are preferred to parameters extracted
|
|
|
|
|
|
// from the query string when they are present in both parts.
|
|
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(uri.Fragment)) |
|
|
|
|
|
{ |
|
|
|
|
|
foreach (var parameter in OpenIddictHelpers.ParseFragment(uri.Fragment)) |
|
|
|
|
|
{ |
|
|
|
|
|
parameters[parameter.Key] = parameter.Value; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
context.Transaction.Request = new OpenIddictRequest(parameters); |
|
|
|
|
|
|
|
|
|
|
|
return default; |
|
|
return default; |
|
|
#else
|
|
|
|
|
|
throw new PlatformNotSupportedException(SR.GetResourceString(SR.ID0446)); |
|
|
|
|
|
#endif
|
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Contains the logic responsible for extracting OpenID Connect requests from the callback URL of a custom tabs intent.
|
|
|
|
|
|
/// Note: this handler is not used when the OpenID Connect request is not a custom tabs intent result.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public sealed class ExtractCustomTabsIntentData<TContext> : IOpenIddictClientHandler<TContext> where TContext : BaseValidatingContext |
|
|
|
|
|
{ |
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets the default descriptor definition assigned to this handler.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public static OpenIddictClientHandlerDescriptor Descriptor { get; } |
|
|
|
|
|
= OpenIddictClientHandlerDescriptor.CreateBuilder<TContext>() |
|
|
|
|
|
.AddFilter<RequireCustomTabsIntentData>() |
|
|
|
|
|
.UseSingletonHandler<ExtractCustomTabsIntentData<TContext>>() |
|
|
|
|
|
.SetOrder(ExtractProtocolActivationParameters<TContext>.Descriptor.Order + 1_000) |
|
|
|
|
|
.SetType(OpenIddictClientHandlerType.BuiltIn) |
|
|
|
|
|
.Build(); |
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
|
[SupportedOSPlatform("android21.0")] |
|
|
|
|
|
public ValueTask HandleAsync(TContext context) |
|
|
|
|
|
{ |
|
|
|
|
|
if (context is null) |
|
|
|
|
|
{ |
|
|
|
|
|
throw new ArgumentNullException(nameof(context)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#if SUPPORTS_ANDROID
|
|
|
|
|
|
if (context.Transaction.GetCustomTabsIntentData() |
|
|
|
|
|
is not NativeUri url || !Uri.TryCreate(url.ToString(), UriKind.Absolute, out Uri? uri)) |
|
|
|
|
|
{ |
|
|
|
|
|
throw new InvalidOperationException(SR.GetResourceString(SR.ID0393)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var parameters = new Dictionary<string, StringValues>(StringComparer.Ordinal); |
|
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(uri.Query)) |
|
|
|
|
|
{ |
|
|
|
|
|
foreach (var parameter in OpenIddictHelpers.ParseQuery(uri.Query)) |
|
|
|
|
|
{ |
|
|
|
|
|
parameters[parameter.Key] = parameter.Value; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Note: the fragment is always processed after the query string to ensure that
|
|
|
|
|
|
// parameters extracted from the fragment are preferred to parameters extracted
|
|
|
|
|
|
// from the query string when they are present in both parts.
|
|
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(uri.Fragment)) |
|
|
|
|
|
{ |
|
|
|
|
|
foreach (var parameter in OpenIddictHelpers.ParseFragment(uri.Fragment)) |
|
|
|
|
|
{ |
|
|
|
|
|
parameters[parameter.Key] = parameter.Value; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
context.Transaction.Request = new OpenIddictRequest(parameters); |
|
|
|
|
|
|
|
|
|
|
|
return default; |
|
|
|
|
|
#else
|
|
|
|
|
|
throw new PlatformNotSupportedException(SR.GetResourceString(SR.ID0446)); |
|
|
|
|
|
#endif
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -805,6 +625,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers |
|
|
/// requests from the response data of a web authentication result.
|
|
|
/// requests from the response data of a web authentication result.
|
|
|
/// Note: this handler is not used when the OpenID Connect request is not a web authentication result.
|
|
|
/// Note: this handler is not used when the OpenID Connect request is not a web authentication result.
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
|
|
|
[Obsolete("This event handler is obsolete and will be removed in a future version.")] |
|
|
public sealed class ExtractWebAuthenticationResultData<TContext> : IOpenIddictClientHandler<TContext> where TContext : BaseValidatingContext |
|
|
public sealed class ExtractWebAuthenticationResultData<TContext> : IOpenIddictClientHandler<TContext> where TContext : BaseValidatingContext |
|
|
{ |
|
|
{ |
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
@ -814,56 +635,13 @@ public static partial class OpenIddictClientSystemIntegrationHandlers |
|
|
= OpenIddictClientHandlerDescriptor.CreateBuilder<TContext>() |
|
|
= OpenIddictClientHandlerDescriptor.CreateBuilder<TContext>() |
|
|
.AddFilter<RequireWebAuthenticationResult>() |
|
|
.AddFilter<RequireWebAuthenticationResult>() |
|
|
.UseSingletonHandler<ExtractWebAuthenticationResultData<TContext>>() |
|
|
.UseSingletonHandler<ExtractWebAuthenticationResultData<TContext>>() |
|
|
.SetOrder(ExtractCustomTabsIntentData<TContext>.Descriptor.Order + 1_000) |
|
|
.SetOrder(ExtractPlatformCallbackParameters<TContext>.Descriptor.Order + 1_000) |
|
|
.SetType(OpenIddictClientHandlerType.BuiltIn) |
|
|
.SetType(OpenIddictClientHandlerType.BuiltIn) |
|
|
.Build(); |
|
|
.Build(); |
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
/// <inheritdoc/>
|
|
|
[SupportedOSPlatform("windows10.0.17763")] |
|
|
|
|
|
public ValueTask HandleAsync(TContext context) |
|
|
public ValueTask HandleAsync(TContext context) |
|
|
{ |
|
|
=> throw new NotSupportedException(SR.GetResourceString(SR.ID0403)); |
|
|
if (context is null) |
|
|
|
|
|
{ |
|
|
|
|
|
throw new ArgumentNullException(nameof(context)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#if SUPPORTS_WINDOWS_RUNTIME
|
|
|
|
|
|
if (context.Transaction.GetWebAuthenticationResult() |
|
|
|
|
|
is not { ResponseStatus: WebAuthenticationStatus.Success, ResponseData: string data } || |
|
|
|
|
|
!Uri.TryCreate(data, UriKind.Absolute, out Uri? uri)) |
|
|
|
|
|
{ |
|
|
|
|
|
throw new InvalidOperationException(SR.GetResourceString(SR.ID0393)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var parameters = new Dictionary<string, StringValues>(StringComparer.Ordinal); |
|
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(uri.Query)) |
|
|
|
|
|
{ |
|
|
|
|
|
foreach (var parameter in OpenIddictHelpers.ParseQuery(uri.Query)) |
|
|
|
|
|
{ |
|
|
|
|
|
parameters[parameter.Key] = parameter.Value; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Note: the fragment is always processed after the query string to ensure that
|
|
|
|
|
|
// parameters extracted from the fragment are preferred to parameters extracted
|
|
|
|
|
|
// from the query string when they are present in both parts.
|
|
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(uri.Fragment)) |
|
|
|
|
|
{ |
|
|
|
|
|
foreach (var parameter in OpenIddictHelpers.ParseFragment(uri.Fragment)) |
|
|
|
|
|
{ |
|
|
|
|
|
parameters[parameter.Key] = parameter.Value; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
context.Transaction.Request = new OpenIddictRequest(parameters); |
|
|
|
|
|
|
|
|
|
|
|
return default; |
|
|
|
|
|
#else
|
|
|
|
|
|
throw new PlatformNotSupportedException(SR.GetResourceString(SR.ID0392)); |
|
|
|
|
|
#endif
|
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
@ -2056,7 +1834,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers |
|
|
// the server support response_mode=fragment, use it if the response types contain
|
|
|
// the server support response_mode=fragment, use it if the response types contain
|
|
|
// a value that prevents response_mode=query from being used (token/id_token).
|
|
|
// a value that prevents response_mode=query from being used (token/id_token).
|
|
|
({ Count: > 0 } client, { Count: > 0 } server) when |
|
|
({ Count: > 0 } client, { Count: > 0 } server) when |
|
|
OpenIddictClientSystemIntegrationHelpers.IsWebAuthenticationBrokerSupported() && |
|
|
IsWebAuthenticationBrokerSupported() && |
|
|
IsAuthenticationMode(OpenIddictClientSystemIntegrationAuthenticationMode.WebAuthenticationBroker) && |
|
|
IsAuthenticationMode(OpenIddictClientSystemIntegrationAuthenticationMode.WebAuthenticationBroker) && |
|
|
client.Contains(ResponseModes.Fragment) && server.Contains(ResponseModes.Fragment) && |
|
|
client.Contains(ResponseModes.Fragment) && server.Contains(ResponseModes.Fragment) && |
|
|
(types.Contains(ResponseTypes.IdToken) || types.Contains(ResponseTypes.Token)) |
|
|
(types.Contains(ResponseTypes.IdToken) || types.Contains(ResponseTypes.Token)) |
|
|
@ -2067,7 +1845,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers |
|
|
// assume it is supported and use it if the response types contain a value that
|
|
|
// assume it is supported and use it if the response types contain a value that
|
|
|
// prevents response_mode=query from being used (token/id_token).
|
|
|
// prevents response_mode=query from being used (token/id_token).
|
|
|
({ Count: > 0 } client, { Count: 0 }) when |
|
|
({ Count: > 0 } client, { Count: 0 }) when |
|
|
OpenIddictClientSystemIntegrationHelpers.IsWebAuthenticationBrokerSupported() && |
|
|
IsWebAuthenticationBrokerSupported() && |
|
|
IsAuthenticationMode(OpenIddictClientSystemIntegrationAuthenticationMode.WebAuthenticationBroker) && |
|
|
IsAuthenticationMode(OpenIddictClientSystemIntegrationAuthenticationMode.WebAuthenticationBroker) && |
|
|
client.Contains(ResponseModes.Fragment) && |
|
|
client.Contains(ResponseModes.Fragment) && |
|
|
(types.Contains(ResponseTypes.IdToken) || types.Contains(ResponseTypes.Token)) |
|
|
(types.Contains(ResponseTypes.IdToken) || types.Contains(ResponseTypes.Token)) |
|
|
@ -2129,7 +1907,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers |
|
|
// When using the web authentication broker on Windows, if both
|
|
|
// When using the web authentication broker on Windows, if both
|
|
|
// the client and the server support response_mode=fragment, use it.
|
|
|
// the client and the server support response_mode=fragment, use it.
|
|
|
({ Count: > 0 } client, { Count: > 0 } server) when |
|
|
({ Count: > 0 } client, { Count: > 0 } server) when |
|
|
OpenIddictClientSystemIntegrationHelpers.IsWebAuthenticationBrokerSupported() && |
|
|
IsWebAuthenticationBrokerSupported() && |
|
|
IsAuthenticationMode(OpenIddictClientSystemIntegrationAuthenticationMode.WebAuthenticationBroker) && |
|
|
IsAuthenticationMode(OpenIddictClientSystemIntegrationAuthenticationMode.WebAuthenticationBroker) && |
|
|
client.Contains(ResponseModes.Fragment) && server.Contains(ResponseModes.Fragment) |
|
|
client.Contains(ResponseModes.Fragment) && server.Contains(ResponseModes.Fragment) |
|
|
=> ResponseModes.Fragment, |
|
|
=> ResponseModes.Fragment, |
|
|
@ -2610,43 +2388,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers |
|
|
= OpenIddictClientHandlerDescriptor.CreateBuilder<TContext>() |
|
|
= OpenIddictClientHandlerDescriptor.CreateBuilder<TContext>() |
|
|
.AddFilter<RequireProtocolActivation>() |
|
|
.AddFilter<RequireProtocolActivation>() |
|
|
.UseSingletonHandler<ProcessProtocolActivationResponse<TContext>>() |
|
|
.UseSingletonHandler<ProcessProtocolActivationResponse<TContext>>() |
|
|
.SetOrder(ProcessWebAuthenticationResultResponse<TContext>.Descriptor.Order - 1_000) |
|
|
.SetOrder(ProcessPlatformCallbackResponse<TContext>.Descriptor.Order - 1_000) |
|
|
.SetType(OpenIddictClientHandlerType.BuiltIn) |
|
|
|
|
|
.Build(); |
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
|
public ValueTask HandleAsync(TContext context) |
|
|
|
|
|
{ |
|
|
|
|
|
if (context is null) |
|
|
|
|
|
{ |
|
|
|
|
|
throw new ArgumentNullException(nameof(context)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// For both protocol activations (initial or redirected) and web-view-like results,
|
|
|
|
|
|
// no proper response can be generated and eventually displayed to the user. In this
|
|
|
|
|
|
// case, simply stop processing the response and mark the request as fully handled.
|
|
|
|
|
|
//
|
|
|
|
|
|
// Note: this logic applies to both successful and errored responses.
|
|
|
|
|
|
|
|
|
|
|
|
context.HandleRequest(); |
|
|
|
|
|
return default; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Contains the logic responsible for marking OpenID Connect responses returned via a custom tabs intent web as processed.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public sealed class ProcessCustomTabsIntentResponse<TContext> : IOpenIddictClientHandler<TContext> |
|
|
|
|
|
where TContext : BaseRequestContext |
|
|
|
|
|
{ |
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets the default descriptor definition assigned to this handler.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public static OpenIddictClientHandlerDescriptor Descriptor { get; } |
|
|
|
|
|
= OpenIddictClientHandlerDescriptor.CreateBuilder<TContext>() |
|
|
|
|
|
.AddFilter<RequireCustomTabsIntentData>() |
|
|
|
|
|
.UseSingletonHandler<ProcessCustomTabsIntentResponse<TContext>>() |
|
|
|
|
|
.SetOrder(int.MaxValue) |
|
|
|
|
|
.SetType(OpenIddictClientHandlerType.BuiltIn) |
|
|
.SetType(OpenIddictClientHandlerType.BuiltIn) |
|
|
.Build(); |
|
|
.Build(); |
|
|
|
|
|
|
|
|
@ -2670,10 +2412,9 @@ public static partial class OpenIddictClientSystemIntegrationHandlers |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Contains the logic responsible for marking OpenID Connect responses
|
|
|
/// Contains the logic responsible for marking OpenID Connect responses returned via a platform callback.
|
|
|
/// returned via AS web authentication callback URLs as processed.
|
|
|
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
public sealed class ProcessASWebAuthenticationSessionResponse<TContext> : IOpenIddictClientHandler<TContext> |
|
|
public sealed class ProcessPlatformCallbackResponse<TContext> : IOpenIddictClientHandler<TContext> |
|
|
where TContext : BaseRequestContext |
|
|
where TContext : BaseRequestContext |
|
|
{ |
|
|
{ |
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
@ -2681,8 +2422,8 @@ public static partial class OpenIddictClientSystemIntegrationHandlers |
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
public static OpenIddictClientHandlerDescriptor Descriptor { get; } |
|
|
public static OpenIddictClientHandlerDescriptor Descriptor { get; } |
|
|
= OpenIddictClientHandlerDescriptor.CreateBuilder<TContext>() |
|
|
= OpenIddictClientHandlerDescriptor.CreateBuilder<TContext>() |
|
|
.AddFilter<RequireASWebAuthenticationCallbackUrl>() |
|
|
.AddFilter<RequirePlatformCallback>() |
|
|
.UseSingletonHandler<ProcessASWebAuthenticationSessionResponse<TContext>>() |
|
|
.UseSingletonHandler<ProcessPlatformCallbackResponse<TContext>>() |
|
|
.SetOrder(int.MaxValue) |
|
|
.SetOrder(int.MaxValue) |
|
|
.SetType(OpenIddictClientHandlerType.BuiltIn) |
|
|
.SetType(OpenIddictClientHandlerType.BuiltIn) |
|
|
.Build(); |
|
|
.Build(); |
|
|
@ -2710,6 +2451,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers |
|
|
/// Contains the logic responsible for marking OpenID Connect
|
|
|
/// Contains the logic responsible for marking OpenID Connect
|
|
|
/// responses returned via web authentication results as processed.
|
|
|
/// responses returned via web authentication results as processed.
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
|
|
|
[Obsolete("This handler is obsolete and will be removed in a future version.")] |
|
|
public sealed class ProcessWebAuthenticationResultResponse<TContext> : IOpenIddictClientHandler<TContext> |
|
|
public sealed class ProcessWebAuthenticationResultResponse<TContext> : IOpenIddictClientHandler<TContext> |
|
|
where TContext : BaseRequestContext |
|
|
where TContext : BaseRequestContext |
|
|
{ |
|
|
{ |
|
|
|