Browse Source
- OpenIddictClientService.ChallengeUsingBackchannelAsync/AuthenticateWithBackchannelAsync. - Backchannel authentication request pipeline (client authentication negotiation, client assertions, mTLS certificates, System.Net.Http integration, response validation). - CIBA grant support at the token endpoint (auth_req_id, identity token required). - Discovery extraction of the backchannel authentication metadata. - Only enforce the pushed authorization requests requirement for interactive flows.pull/2549/head
14 changed files with 1744 additions and 6 deletions
@ -0,0 +1,41 @@ |
|||
/* |
|||
* Licensed under the Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
|
|||
* See https://github.com/openiddict/openiddict-core for more information concerning
|
|||
* the license and the contributors participating to this project. |
|||
*/ |
|||
|
|||
using System.Collections.Immutable; |
|||
|
|||
namespace OpenIddict.Client.SystemNetHttp; |
|||
|
|||
public static partial class OpenIddictClientSystemNetHttpHandlers |
|||
{ |
|||
public static class Backchannel |
|||
{ |
|||
public static ImmutableArray<OpenIddictClientHandlerDescriptor> DefaultHandlers { get; } = |
|||
[ |
|||
/* |
|||
* Backchannel authentication request processing: |
|||
*/ |
|||
CreateHttpClient<PrepareBackchannelAuthenticationRequestContext>.Descriptor, |
|||
PreparePostHttpRequest<PrepareBackchannelAuthenticationRequestContext>.Descriptor, |
|||
AttachHttpVersion<PrepareBackchannelAuthenticationRequestContext>.Descriptor, |
|||
AttachJsonAcceptHeaders<PrepareBackchannelAuthenticationRequestContext>.Descriptor, |
|||
AttachUserAgentHeader<PrepareBackchannelAuthenticationRequestContext>.Descriptor, |
|||
AttachFromHeader<PrepareBackchannelAuthenticationRequestContext>.Descriptor, |
|||
AttachBasicAuthenticationCredentials<PrepareBackchannelAuthenticationRequestContext>.Descriptor, |
|||
AttachHttpParameters<PrepareBackchannelAuthenticationRequestContext>.Descriptor, |
|||
SendHttpRequest<ApplyBackchannelAuthenticationRequestContext>.Descriptor, |
|||
DisposeHttpRequest<ApplyBackchannelAuthenticationRequestContext>.Descriptor, |
|||
|
|||
/* |
|||
* Backchannel authentication response processing: |
|||
*/ |
|||
DecompressResponseContent<ExtractBackchannelAuthenticationResponseContext>.Descriptor, |
|||
ExtractJsonHttpResponse<ExtractBackchannelAuthenticationResponseContext>.Descriptor, |
|||
ExtractWwwAuthenticateHeader<ExtractBackchannelAuthenticationResponseContext>.Descriptor, |
|||
ValidateHttpResponse<ExtractBackchannelAuthenticationResponseContext>.Descriptor, |
|||
DisposeHttpResponse<ExtractBackchannelAuthenticationResponseContext>.Descriptor |
|||
]; |
|||
} |
|||
} |
|||
@ -0,0 +1,123 @@ |
|||
/* |
|||
* Licensed under the Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
|
|||
* See https://github.com/openiddict/openiddict-core for more information concerning
|
|||
* the license and the contributors participating to this project. |
|||
*/ |
|||
|
|||
namespace OpenIddict.Client; |
|||
|
|||
public static partial class OpenIddictClientEvents |
|||
{ |
|||
/// <summary>
|
|||
/// Represents an event called for each request to the backchannel authentication endpoint
|
|||
/// to give the user code a chance to add parameters to the backchannel authentication request.
|
|||
/// </summary>
|
|||
public sealed class PrepareBackchannelAuthenticationRequestContext : BaseExternalContext |
|||
{ |
|||
/// <summary>
|
|||
/// Creates a new instance of the <see cref="PrepareBackchannelAuthenticationRequestContext"/> class.
|
|||
/// </summary>
|
|||
public PrepareBackchannelAuthenticationRequestContext(OpenIddictClientTransaction transaction) |
|||
: base(transaction) |
|||
{ |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets the request.
|
|||
/// </summary>
|
|||
public OpenIddictRequest Request |
|||
{ |
|||
get => Transaction.Request!; |
|||
set => Transaction.Request = value; |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Represents an event called for each request to the backchannel authentication endpoint
|
|||
/// to send the backchannel authentication request to the remote authorization server.
|
|||
/// </summary>
|
|||
public sealed class ApplyBackchannelAuthenticationRequestContext : BaseExternalContext |
|||
{ |
|||
/// <summary>
|
|||
/// Creates a new instance of the <see cref="ApplyBackchannelAuthenticationRequestContext"/> class.
|
|||
/// </summary>
|
|||
public ApplyBackchannelAuthenticationRequestContext(OpenIddictClientTransaction transaction) |
|||
: base(transaction) |
|||
{ |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets the request.
|
|||
/// </summary>
|
|||
public OpenIddictRequest Request |
|||
{ |
|||
get => Transaction.Request!; |
|||
set => Transaction.Request = value; |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Represents an event called for each backchannel authentication response
|
|||
/// to extract the response parameters from the server response.
|
|||
/// </summary>
|
|||
public sealed class ExtractBackchannelAuthenticationResponseContext : BaseExternalContext |
|||
{ |
|||
/// <summary>
|
|||
/// Creates a new instance of the <see cref="ExtractBackchannelAuthenticationResponseContext"/> class.
|
|||
/// </summary>
|
|||
public ExtractBackchannelAuthenticationResponseContext(OpenIddictClientTransaction transaction) |
|||
: base(transaction) |
|||
{ |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets the request.
|
|||
/// </summary>
|
|||
public OpenIddictRequest Request |
|||
{ |
|||
get => Transaction.Request!; |
|||
set => Transaction.Request = value; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets the response, or <see langword="null"/> if it wasn't extracted yet.
|
|||
/// </summary>
|
|||
public OpenIddictResponse? Response |
|||
{ |
|||
get => Transaction.Response; |
|||
set => Transaction.Response = value; |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Represents an event called for each backchannel authentication response.
|
|||
/// </summary>
|
|||
public sealed class HandleBackchannelAuthenticationResponseContext : BaseExternalContext |
|||
{ |
|||
/// <summary>
|
|||
/// Creates a new instance of the <see cref="HandleBackchannelAuthenticationResponseContext"/> class.
|
|||
/// </summary>
|
|||
public HandleBackchannelAuthenticationResponseContext(OpenIddictClientTransaction transaction) |
|||
: base(transaction) |
|||
{ |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets the request.
|
|||
/// </summary>
|
|||
public OpenIddictRequest Request |
|||
{ |
|||
get => Transaction.Request!; |
|||
set => Transaction.Request = value; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets the response.
|
|||
/// </summary>
|
|||
public OpenIddictResponse Response |
|||
{ |
|||
get => Transaction.Response!; |
|||
set => Transaction.Response = value; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,203 @@ |
|||
/* |
|||
* Licensed under the Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
|
|||
* See https://github.com/openiddict/openiddict-core for more information concerning
|
|||
* the license and the contributors participating to this project. |
|||
*/ |
|||
|
|||
using System.Collections.Immutable; |
|||
using System.Text.Json; |
|||
using Microsoft.Extensions.Logging; |
|||
|
|||
namespace OpenIddict.Client; |
|||
|
|||
public static partial class OpenIddictClientHandlers |
|||
{ |
|||
public static class Backchannel |
|||
{ |
|||
public static ImmutableArray<OpenIddictClientHandlerDescriptor> DefaultHandlers { get; } = |
|||
[ |
|||
/* |
|||
* Backchannel authentication response handling: |
|||
*/ |
|||
ValidateWellKnownParameters.Descriptor, |
|||
HandleErrorResponse.Descriptor, |
|||
ValidateAuthenticationRequestId.Descriptor, |
|||
ValidateExpiration.Descriptor |
|||
]; |
|||
|
|||
/// <summary>
|
|||
/// Contains the logic responsible for validating the well-known parameters contained in the backchannel authentication response.
|
|||
/// </summary>
|
|||
public sealed class ValidateWellKnownParameters : IOpenIddictClientHandler<HandleBackchannelAuthenticationResponseContext> |
|||
{ |
|||
/// <summary>
|
|||
/// Gets the default descriptor definition assigned to this handler.
|
|||
/// </summary>
|
|||
public static OpenIddictClientHandlerDescriptor Descriptor { get; } |
|||
= OpenIddictClientHandlerDescriptor.CreateBuilder<HandleBackchannelAuthenticationResponseContext>() |
|||
.UseSingletonHandler<ValidateWellKnownParameters>() |
|||
.SetOrder(int.MinValue + 100_000) |
|||
.SetType(OpenIddictClientHandlerType.BuiltIn) |
|||
.Build(); |
|||
|
|||
/// <inheritdoc/>
|
|||
public ValueTask HandleAsync(HandleBackchannelAuthenticationResponseContext context) |
|||
{ |
|||
ArgumentNullException.ThrowIfNull(context); |
|||
|
|||
foreach (var parameter in context.Response.GetParameters()) |
|||
{ |
|||
if (!ValidateParameterType(parameter.Key, parameter.Value)) |
|||
{ |
|||
context.Reject( |
|||
error: Errors.ServerError, |
|||
description: SR.FormatID2107(parameter.Key), |
|||
uri: SR.FormatID8000(SR.ID2107)); |
|||
|
|||
return ValueTask.CompletedTask; |
|||
} |
|||
} |
|||
|
|||
return ValueTask.CompletedTask; |
|||
|
|||
static bool ValidateParameterType(string name, OpenIddictParameter value) => name switch |
|||
{ |
|||
// The following parameters MUST be formatted as unique strings:
|
|||
Parameters.AuthReqId or Parameters.Error or Parameters.ErrorDescription or Parameters.ErrorUri |
|||
=> ((JsonElement) value).ValueKind is JsonValueKind.String, |
|||
|
|||
// The following parameters MUST be formatted as positive numbers:
|
|||
Parameters.ExpiresIn or Parameters.Interval |
|||
=> (JsonElement) value is { ValueKind: JsonValueKind.Number } element && |
|||
element.TryGetDecimal(out decimal result) && result is >= 0, |
|||
|
|||
// Parameters that are not in the well-known list can be of any type.
|
|||
_ => true |
|||
}; |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Contains the logic responsible for surfacing potential errors from the backchannel authentication response.
|
|||
/// </summary>
|
|||
public sealed class HandleErrorResponse : IOpenIddictClientHandler<HandleBackchannelAuthenticationResponseContext> |
|||
{ |
|||
/// <summary>
|
|||
/// Gets the default descriptor definition assigned to this handler.
|
|||
/// </summary>
|
|||
public static OpenIddictClientHandlerDescriptor Descriptor { get; } |
|||
= OpenIddictClientHandlerDescriptor.CreateBuilder<HandleBackchannelAuthenticationResponseContext>() |
|||
.UseSingletonHandler<HandleErrorResponse>() |
|||
.SetOrder(ValidateWellKnownParameters.Descriptor.Order + 1_000) |
|||
.SetType(OpenIddictClientHandlerType.BuiltIn) |
|||
.Build(); |
|||
|
|||
/// <inheritdoc/>
|
|||
public ValueTask HandleAsync(HandleBackchannelAuthenticationResponseContext context) |
|||
{ |
|||
ArgumentNullException.ThrowIfNull(context); |
|||
|
|||
// For more information, see
|
|||
// https://openid.net/specs/openid-client-initiated-backchannel-authentication-core-1_0.html#rfc.section.13.
|
|||
if (!string.IsNullOrEmpty(context.Response.Error)) |
|||
{ |
|||
context.Logger.LogInformation(6306, SR.GetResourceString(SR.ID6306), context.Response); |
|||
|
|||
context.Reject( |
|||
error: context.Response.Error switch |
|||
{ |
|||
Errors.AccessDenied => Errors.AccessDenied, |
|||
Errors.ExpiredLoginHintToken => Errors.ExpiredLoginHintToken, |
|||
Errors.InvalidBindingMessage => Errors.InvalidBindingMessage, |
|||
Errors.InvalidClient => Errors.InvalidRequest, |
|||
Errors.InvalidRequest => Errors.InvalidRequest, |
|||
Errors.InvalidScope => Errors.InvalidScope, |
|||
Errors.InvalidUserCode => Errors.InvalidUserCode, |
|||
Errors.MissingUserCode => Errors.MissingUserCode, |
|||
Errors.UnauthorizedClient => Errors.UnauthorizedClient, |
|||
Errors.UnknownUserId => Errors.UnknownUserId, |
|||
_ => Errors.ServerError |
|||
}, |
|||
description: SR.GetResourceString(SR.ID2219), |
|||
uri: SR.FormatID8000(SR.ID2219)); |
|||
|
|||
return ValueTask.CompletedTask; |
|||
} |
|||
|
|||
return ValueTask.CompletedTask; |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Contains the logic responsible for validating the authentication
|
|||
/// request identifier contained in the backchannel authentication response.
|
|||
/// </summary>
|
|||
public sealed class ValidateAuthenticationRequestId : IOpenIddictClientHandler<HandleBackchannelAuthenticationResponseContext> |
|||
{ |
|||
/// <summary>
|
|||
/// Gets the default descriptor definition assigned to this handler.
|
|||
/// </summary>
|
|||
public static OpenIddictClientHandlerDescriptor Descriptor { get; } |
|||
= OpenIddictClientHandlerDescriptor.CreateBuilder<HandleBackchannelAuthenticationResponseContext>() |
|||
.UseSingletonHandler<ValidateAuthenticationRequestId>() |
|||
.SetOrder(HandleErrorResponse.Descriptor.Order + 1_000) |
|||
.SetType(OpenIddictClientHandlerType.BuiltIn) |
|||
.Build(); |
|||
|
|||
/// <inheritdoc/>
|
|||
public ValueTask HandleAsync(HandleBackchannelAuthenticationResponseContext context) |
|||
{ |
|||
ArgumentNullException.ThrowIfNull(context); |
|||
|
|||
// Return an error if the mandatory "auth_req_id" parameter is missing.
|
|||
if (string.IsNullOrEmpty(context.Response.AuthReqId)) |
|||
{ |
|||
context.Reject( |
|||
error: Errors.ServerError, |
|||
description: SR.FormatID2168(Parameters.AuthReqId), |
|||
uri: SR.FormatID8000(SR.ID2168)); |
|||
|
|||
return ValueTask.CompletedTask; |
|||
} |
|||
|
|||
return ValueTask.CompletedTask; |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Contains the logic responsible for validating the "expires_in"
|
|||
/// parameter contained in the backchannel authentication response.
|
|||
/// </summary>
|
|||
public sealed class ValidateExpiration : IOpenIddictClientHandler<HandleBackchannelAuthenticationResponseContext> |
|||
{ |
|||
/// <summary>
|
|||
/// Gets the default descriptor definition assigned to this handler.
|
|||
/// </summary>
|
|||
public static OpenIddictClientHandlerDescriptor Descriptor { get; } |
|||
= OpenIddictClientHandlerDescriptor.CreateBuilder<HandleBackchannelAuthenticationResponseContext>() |
|||
.UseSingletonHandler<ValidateExpiration>() |
|||
.SetOrder(ValidateAuthenticationRequestId.Descriptor.Order + 1_000) |
|||
.SetType(OpenIddictClientHandlerType.BuiltIn) |
|||
.Build(); |
|||
|
|||
/// <inheritdoc/>
|
|||
public ValueTask HandleAsync(HandleBackchannelAuthenticationResponseContext context) |
|||
{ |
|||
ArgumentNullException.ThrowIfNull(context); |
|||
|
|||
// Return an error if the mandatory "expires_in" parameter is missing.
|
|||
if (context.Response.ExpiresIn is null) |
|||
{ |
|||
context.Reject( |
|||
error: Errors.ServerError, |
|||
description: SR.FormatID2168(Parameters.ExpiresIn), |
|||
uri: SR.FormatID8000(SR.ID2168)); |
|||
|
|||
return ValueTask.CompletedTask; |
|||
} |
|||
|
|||
return ValueTask.CompletedTask; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,236 @@ |
|||
using System.Security.Claims; |
|||
using System.Text.Json; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Microsoft.Extensions.Options; |
|||
using Xunit; |
|||
using static OpenIddict.Client.OpenIddictClientEvents; |
|||
using static OpenIddict.Client.OpenIddictClientHandlers; |
|||
|
|||
namespace OpenIddict.Client.Tests; |
|||
|
|||
public class OpenIddictClientHandlersBackchannelTests |
|||
{ |
|||
[Fact] |
|||
public async Task EvaluateBackchannelAuthenticationRequest_RequestIsSentForCibaGrant() |
|||
{ |
|||
// Arrange
|
|||
using var provider = CreateProvider(); |
|||
var context = CreateChallengeContext(provider); |
|||
context.LoginHint = "bob@fabrikam.com"; |
|||
|
|||
// Act
|
|||
await new EvaluateBackchannelAuthenticationRequest().HandleAsync(context); |
|||
|
|||
// Assert
|
|||
Assert.True(context.SendBackchannelAuthenticationRequest); |
|||
} |
|||
|
|||
[Theory] |
|||
[InlineData(null, null, null)] |
|||
[InlineData("bob@fabrikam.com", "token", null)] |
|||
[InlineData("bob@fabrikam.com", null, "id_token")] |
|||
public async Task EvaluateBackchannelAuthenticationRequest_ThrowsAnExceptionForInvalidHints(string? hint, string? token, string? identity) |
|||
{ |
|||
// Arrange
|
|||
using var provider = CreateProvider(); |
|||
var context = CreateChallengeContext(provider); |
|||
context.LoginHint = hint; |
|||
context.LoginHintToken = token; |
|||
context.IdentityTokenHint = identity; |
|||
|
|||
// Act and assert
|
|||
var exception = await Assert.ThrowsAsync<InvalidOperationException>( |
|||
async () => await new EvaluateBackchannelAuthenticationRequest().HandleAsync(context)); |
|||
|
|||
Assert.Equal(SR.GetResourceString(SR.ID0541), exception.Message); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task AttachBackchannelAuthenticationRequestParameters_ParametersAreAttached() |
|||
{ |
|||
// Arrange
|
|||
using var provider = CreateProvider(); |
|||
var context = CreateChallengeContext(provider); |
|||
context.BindingMessage = "W4SCT"; |
|||
context.LoginHint = "bob@fabrikam.com"; |
|||
context.RequestedExpiry = TimeSpan.FromSeconds(119.5); |
|||
context.Scopes.Add(Scopes.Profile); |
|||
|
|||
// Act
|
|||
await new AttachBackchannelAuthenticationRequestParameters().HandleAsync(context); |
|||
|
|||
// Assert
|
|||
Assert.NotNull(context.BackchannelAuthenticationRequest); |
|||
Assert.Equal("openid profile", context.BackchannelAuthenticationRequest.Scope); |
|||
Assert.Equal("bob@fabrikam.com", context.BackchannelAuthenticationRequest.LoginHint); |
|||
Assert.Equal("W4SCT", context.BackchannelAuthenticationRequest.BindingMessage); |
|||
Assert.Equal(120, context.BackchannelAuthenticationRequest.RequestedExpiry); |
|||
Assert.Null(context.BackchannelAuthenticationRequest.IdTokenHint); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task ValidateAuthenticationRequestId_MissingIdentifierCausesAnError() |
|||
{ |
|||
// Arrange
|
|||
using var provider = CreateProvider(); |
|||
var context = CreateResponseContext(provider, new OpenIddictResponse { ExpiresIn = 120 }); |
|||
|
|||
// Act
|
|||
await new Backchannel.ValidateAuthenticationRequestId().HandleAsync(context); |
|||
|
|||
// Assert
|
|||
Assert.True(context.IsRejected); |
|||
Assert.Equal(Errors.ServerError, context.Error); |
|||
Assert.Equal(SR.FormatID2168(Parameters.AuthReqId), context.ErrorDescription); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task ValidateExpiration_MissingExpirationCausesAnError() |
|||
{ |
|||
// Arrange
|
|||
using var provider = CreateProvider(); |
|||
var context = CreateResponseContext(provider, new OpenIddictResponse { AuthReqId = "id" }); |
|||
|
|||
// Act
|
|||
await new Backchannel.ValidateExpiration().HandleAsync(context); |
|||
|
|||
// Assert
|
|||
Assert.True(context.IsRejected); |
|||
Assert.Equal(SR.FormatID2168(Parameters.ExpiresIn), context.ErrorDescription); |
|||
} |
|||
|
|||
[Theory] |
|||
[InlineData(Errors.UnknownUserId, Errors.UnknownUserId)] |
|||
[InlineData(Errors.ExpiredLoginHintToken, Errors.ExpiredLoginHintToken)] |
|||
[InlineData(Errors.InvalidClient, Errors.InvalidRequest)] |
|||
[InlineData("custom_error", Errors.ServerError)] |
|||
public async Task HandleErrorResponse_ErrorsAreMapped(string error, string expected) |
|||
{ |
|||
// Arrange
|
|||
using var provider = CreateProvider(); |
|||
var context = CreateResponseContext(provider, new OpenIddictResponse { Error = error }); |
|||
|
|||
// Act
|
|||
await new Backchannel.HandleErrorResponse().HandleAsync(context); |
|||
|
|||
// Assert
|
|||
Assert.True(context.IsRejected); |
|||
Assert.Equal(expected, context.Error); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task ValidateWellKnownParameters_InvalidAuthenticationRequestIdTypeCausesAnError() |
|||
{ |
|||
// Arrange
|
|||
using var provider = CreateProvider(); |
|||
var context = CreateResponseContext(provider, new OpenIddictResponse( |
|||
JsonSerializer.Deserialize<JsonElement>("""{ "auth_req_id": 42, "expires_in": 120 }"""))); |
|||
|
|||
// Act
|
|||
await new Backchannel.ValidateWellKnownParameters().HandleAsync(context); |
|||
|
|||
// Assert
|
|||
Assert.True(context.IsRejected); |
|||
Assert.Equal(SR.FormatID2107(Parameters.AuthReqId), context.ErrorDescription); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task ExtractBackchannelAuthenticationEndpoint_MetadataIsExtracted() |
|||
{ |
|||
// Arrange
|
|||
using var provider = CreateProvider(); |
|||
var options = provider.GetRequiredService<IOptionsMonitor<OpenIddictClientOptions>>().CurrentValue; |
|||
|
|||
var context = new HandleConfigurationResponseContext(new OpenIddictClientTransaction |
|||
{ |
|||
CancellationToken = CancellationToken.None, |
|||
Configuration = new OpenIddictConfiguration(), |
|||
Options = options, |
|||
Registration = options.Registrations[0], |
|||
ServiceProvider = provider |
|||
}) |
|||
{ |
|||
Response = new OpenIddictResponse(JsonSerializer.Deserialize<JsonElement>("""
|
|||
{ |
|||
"backchannel_authentication_endpoint": "https://www.contoso.com/connect/ciba", |
|||
"backchannel_token_delivery_modes_supported": [ "poll" ], |
|||
"backchannel_user_code_parameter_supported": false |
|||
} |
|||
"""))
|
|||
}; |
|||
|
|||
// Act
|
|||
await new OpenIddictClientHandlers.Discovery.ExtractBackchannelAuthenticationEndpoint().HandleAsync(context); |
|||
|
|||
// Assert
|
|||
Assert.False(context.IsRejected); |
|||
Assert.Equal(new Uri("https://www.contoso.com/connect/ciba"), context.Configuration.BackchannelAuthenticationEndpoint); |
|||
Assert.Contains(BackchannelTokenDeliveryModes.Poll, context.Configuration.BackchannelTokenDeliveryModesSupported); |
|||
Assert.False(context.Configuration.BackchannelUserCodeParameterSupported); |
|||
} |
|||
|
|||
private static ServiceProvider CreateProvider() |
|||
{ |
|||
var services = new ServiceCollection(); |
|||
|
|||
services.AddOpenIddict() |
|||
.AddClient(options => |
|||
{ |
|||
options.AllowClientInitiatedBackchannelAuthenticationFlow(); |
|||
|
|||
options.AddEphemeralEncryptionKey() |
|||
.AddEphemeralSigningKey(); |
|||
|
|||
options.AddRegistration(new OpenIddictClientRegistration |
|||
{ |
|||
ClientId = "Fabrikam", |
|||
Configuration = new OpenIddictConfiguration |
|||
{ |
|||
Issuer = new Uri("https://www.contoso.com/", UriKind.Absolute) |
|||
}, |
|||
Issuer = new Uri("https://www.contoso.com/", UriKind.Absolute) |
|||
}); |
|||
}); |
|||
|
|||
return services.BuildServiceProvider(); |
|||
} |
|||
|
|||
private static ProcessChallengeContext CreateChallengeContext(IServiceProvider provider) |
|||
{ |
|||
var options = provider.GetRequiredService<IOptionsMonitor<OpenIddictClientOptions>>().CurrentValue; |
|||
|
|||
return new ProcessChallengeContext(new OpenIddictClientTransaction |
|||
{ |
|||
CancellationToken = CancellationToken.None, |
|||
Configuration = new OpenIddictConfiguration(), |
|||
Options = options, |
|||
Registration = options.Registrations[0], |
|||
Request = new OpenIddictRequest(), |
|||
ServiceProvider = provider |
|||
}) |
|||
{ |
|||
ClientId = "Fabrikam", |
|||
GrantType = GrantTypes.Ciba, |
|||
Principal = new ClaimsPrincipal(new ClaimsIdentity()) |
|||
}; |
|||
} |
|||
|
|||
private static HandleBackchannelAuthenticationResponseContext CreateResponseContext( |
|||
IServiceProvider provider, OpenIddictResponse response) |
|||
{ |
|||
var options = provider.GetRequiredService<IOptionsMonitor<OpenIddictClientOptions>>().CurrentValue; |
|||
|
|||
return new HandleBackchannelAuthenticationResponseContext(new OpenIddictClientTransaction |
|||
{ |
|||
CancellationToken = CancellationToken.None, |
|||
Configuration = new OpenIddictConfiguration(), |
|||
Options = options, |
|||
Registration = options.Registrations[0], |
|||
ServiceProvider = provider |
|||
}) |
|||
{ |
|||
Request = new OpenIddictRequest(), |
|||
Response = response |
|||
}; |
|||
} |
|||
} |
|||
Loading…
Reference in new issue