Skip to content

Commit 8673009

Browse files
committed
Update the system integration package to restore the ambient request for marshalled authentication demands
1 parent 9aab50a commit 8673009

File tree

3 files changed

+52
-2
lines changed

3 files changed

+52
-2
lines changed

src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHandlers.cs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
3939
*/
4040
WaitMarshalledAuthentication.Descriptor,
4141

42+
RestoreRequestFromMarshalledContext.Descriptor,
4243
RestoreClientRegistrationFromMarshalledContext.Descriptor,
4344

4445
EvaluateValidatedUpfrontTokensForMarshalledContext.Descriptor,
@@ -661,6 +662,48 @@ public async ValueTask HandleAsync(ProcessAuthenticationContext context)
661662
}
662663
}
663664

665+
/// <summary>
666+
/// Contains the logic responsible for restoring the request from the marshalled authentication context, if applicable.
667+
/// </summary>
668+
public sealed class RestoreRequestFromMarshalledContext : IOpenIddictClientHandler<ProcessAuthenticationContext>
669+
{
670+
private readonly OpenIddictClientSystemIntegrationMarshal _marshal;
671+
672+
public RestoreRequestFromMarshalledContext(OpenIddictClientSystemIntegrationMarshal marshal)
673+
=> _marshal = marshal ?? throw new ArgumentNullException(nameof(marshal));
674+
675+
/// <summary>
676+
/// Gets the default descriptor definition assigned to this handler.
677+
/// </summary>
678+
public static OpenIddictClientHandlerDescriptor Descriptor { get; }
679+
= OpenIddictClientHandlerDescriptor.CreateBuilder<ProcessAuthenticationContext>()
680+
.AddFilter<RequireAuthenticationNonce>()
681+
.UseSingletonHandler<RestoreRequestFromMarshalledContext>()
682+
.SetOrder(WaitMarshalledAuthentication.Descriptor.Order + 250)
683+
.SetType(OpenIddictClientHandlerType.BuiltIn)
684+
.Build();
685+
686+
/// <inheritdoc/>
687+
public ValueTask HandleAsync(ProcessAuthenticationContext context)
688+
{
689+
ArgumentNullException.ThrowIfNull(context);
690+
691+
Debug.Assert(!string.IsNullOrEmpty(context.Nonce), SR.GetResourceString(SR.ID4019));
692+
693+
context.Request = context.EndpointType switch
694+
{
695+
// When the authentication demand is marshalled from a different context, restore the request from the
696+
// other instance so that custom parameters can be resolved from the marshalled context, if necessary.
697+
OpenIddictClientEndpointType.Unknown when _marshal.TryGetResult(context.Nonce, out var notification)
698+
=> notification.Request,
699+
700+
_ => context.Request
701+
};
702+
703+
return ValueTask.CompletedTask;
704+
}
705+
}
706+
664707
/// <summary>
665708
/// Contains the logic responsible for restoring the client registration and
666709
/// configuration from the marshalled authentication context, if applicable.

src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ ProviderTypes.Trovo when context.GrantType is GrantTypes.RefreshToken
524524
// For more information, see
525525
// https://www.zoho.com/accounts/protocol/oauth/multi-dc/client-authorization.html.
526526
ProviderTypes.Zoho when context.GrantType is GrantTypes.AuthorizationCode
527-
=> ((string?) context.Request?["location"])?.ToUpperInvariant() switch
527+
=> ((string?) context.Request["location"])?.ToUpperInvariant() switch
528528
{
529529
"AU" => new Uri("https://accounts.zoho.com.au/oauth/v2/token", UriKind.Absolute),
530530
"CA" => new Uri("https://accounts.zohocloud.ca/oauth/v2/token", UriKind.Absolute),
@@ -1077,7 +1077,7 @@ ProviderTypes.SuperOffice when
10771077
// For more information, see
10781078
// https://www.zoho.com/accounts/protocol/oauth/multi-dc/client-authorization.html.
10791079
ProviderTypes.Zoho when context.GrantType is GrantTypes.AuthorizationCode
1080-
=> ((string?) context.Request?["location"])?.ToUpperInvariant() switch
1080+
=> ((string?) context.Request["location"])?.ToUpperInvariant() switch
10811081
{
10821082
"AU" => new Uri("https://accounts.zoho.com.au/oauth/user/info", UriKind.Absolute),
10831083
"CA" => new Uri("https://accounts.zohocloud.ca/oauth/user/info", UriKind.Absolute),

src/OpenIddict.Client/OpenIddictClientService.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ public async ValueTask<InteractiveAuthenticationResult> AuthenticateInteractivel
272272
{
273273
CancellationToken = request.CancellationToken,
274274
Nonce = request.Nonce,
275+
Request = new(),
275276
TokenEndpointClientCertificate = request.TokenBindingCertificate,
276277
TokenRequest = request.AdditionalTokenRequestParameters
277278
is Dictionary<string, OpenIddictParameter> parameters ? new(parameters) : new()
@@ -430,6 +431,7 @@ public async ValueTask<ClientCredentialsAuthenticationResult> AuthenticateWithCl
430431
Issuer = request.Issuer,
431432
ProviderName = request.ProviderName,
432433
RegistrationId = request.RegistrationId,
434+
Request = new(),
433435
TokenRequest = request.AdditionalTokenRequestParameters
434436
is Dictionary<string, OpenIddictParameter> parameters ? new(parameters) : new()
435437
};
@@ -521,6 +523,7 @@ GrantTypes.DeviceCode or GrantTypes.Implicit or
521523
GrantType = request.GrantType,
522524
ProviderName = request.ProviderName,
523525
RegistrationId = request.RegistrationId,
526+
Request = new(),
524527
TokenEndpointClientCertificate = request.TokenBindingCertificate,
525528
TokenRequest = request.AdditionalTokenRequestParameters
526529
is Dictionary<string, OpenIddictParameter> parameters ? new(parameters) : new()
@@ -616,6 +619,7 @@ public async ValueTask<DeviceAuthenticationResult> AuthenticateWithDeviceAsync(D
616619
Issuer = request.Issuer,
617620
ProviderName = request.ProviderName,
618621
RegistrationId = request.RegistrationId,
622+
Request = new(),
619623
TokenEndpointClientCertificate = request.TokenBindingCertificate,
620624
TokenRequest = request.AdditionalTokenRequestParameters
621625
is Dictionary<string, OpenIddictParameter> parameters ? new(parameters) : new()
@@ -801,6 +805,7 @@ public async ValueTask<PasswordAuthenticationResult> AuthenticateWithPasswordAsy
801805
Password = request.Password,
802806
ProviderName = request.ProviderName,
803807
RegistrationId = request.RegistrationId,
808+
Request = new(),
804809
TokenEndpointClientCertificate = request.TokenBindingCertificate,
805810
TokenRequest = request.AdditionalTokenRequestParameters
806811
is Dictionary<string, OpenIddictParameter> parameters ? new(parameters) : new(),
@@ -889,6 +894,7 @@ public async ValueTask<TokenExchangeAuthenticationResult> AuthenticateWithTokenE
889894
Issuer = request.Issuer,
890895
ProviderName = request.ProviderName,
891896
RegistrationId = request.RegistrationId,
897+
Request = new(),
892898
RequestedTokenType = request.RequestedTokenType,
893899
SubjectToken = request.SubjectToken,
894900
SubjectTokenType = request.SubjectTokenType,
@@ -975,6 +981,7 @@ public async ValueTask<RefreshTokenAuthenticationResult> AuthenticateWithRefresh
975981
ProviderName = request.ProviderName,
976982
RefreshToken = request.RefreshToken,
977983
RegistrationId = request.RegistrationId,
984+
Request = new(),
978985
TokenEndpointClientCertificate = request.TokenBindingCertificate,
979986
TokenRequest = request.AdditionalTokenRequestParameters
980987
is Dictionary<string, OpenIddictParameter> parameters ? new(parameters) : new()

0 commit comments

Comments
 (0)