Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for extraQueryParameters in Blazor WASM / MSAL #30798

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Components/Components.slnf
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"src\\Http\\Http.Extensions\\src\\Microsoft.AspNetCore.Http.Extensions.csproj",
"src\\Http\\Http.Features\\src\\Microsoft.AspNetCore.Http.Features.csproj",
"src\\Http\\Http\\src\\Microsoft.AspNetCore.Http.csproj",
"src\\Http\\Metadata\\src\\Microsoft.AspNetCore.Metadata.csproj",
"src\\Http\\Routing.Abstractions\\src\\Microsoft.AspNetCore.Routing.Abstractions.csproj",
"src\\Http\\Routing\\src\\Microsoft.AspNetCore.Routing.csproj",
"src\\Http\\WebUtilities\\src\\Microsoft.AspNetCore.WebUtilities.csproj",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ class MsalAuthorizeService implements AuthorizeService {
const request: Msal.AuthorizationUrlRequest = {
redirectUri: this._settings.auth?.redirectUri,
state: await this.saveState(state),
scopes: []
scopes: [],
extraQueryParameters: state.extraQueryParameters
};

if (this._settings.defaultAccessTokenScopes && this._settings.defaultAccessTokenScopes.length > 0) {
Expand Down Expand Up @@ -180,7 +181,8 @@ class MsalAuthorizeService implements AuthorizeService {
const silentRequest : Msal.SilentRequest = {
redirectUri: request.redirectUri,
account: account,
scopes: request?.scopes?.concat(request.extraScopesToConsent || []) || []
scopes: request?.scopes?.concat(request.extraScopesToConsent || []) || [],
extraQueryParameters: request.extraQueryParameters
};
await this._msalApplication.acquireTokenSilent(silentRequest);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.Collections.Generic;

namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication
{
/// <summary>
Expand All @@ -13,5 +15,10 @@ public class RemoteAuthenticationState
/// It must be a url within the page.
/// </summary>
public string ReturnUrl { get; set; }

/// <summary>
/// Gets or sets additional query parameters.
/// </summary>
public Dictionary<string, string> ExtraQueryParameters { get; set; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The right place for this is the MSAL provider options, this is not a feature all our implementations offer and not something we plan to do at the moment.

}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#nullable enable
~Microsoft.AspNetCore.Components.WebAssembly.Authentication.OidcProviderOptions.AdditionalProviderParameters.get -> System.Collections.Generic.IDictionary<string, string>
~Microsoft.AspNetCore.Components.WebAssembly.Authentication.RemoteAuthenticationService<TRemoteAuthenticationState, TAccount, TProviderOptions>.RemoteAuthenticationService(Microsoft.JSInterop.IJSRuntime jsRuntime, Microsoft.Extensions.Options.IOptionsSnapshot<Microsoft.AspNetCore.Components.WebAssembly.Authentication.RemoteAuthenticationOptions<TProviderOptions>> options, Microsoft.AspNetCore.Components.NavigationManager navigation, Microsoft.AspNetCore.Components.WebAssembly.Authentication.AccountClaimsPrincipalFactory<TAccount> accountClaimsPrincipalFactory) -> void
*REMOVED*~Microsoft.AspNetCore.Components.WebAssembly.Authentication.RemoteAuthenticationService<TRemoteAuthenticationState, TAccount, TProviderOptions>.RemoteAuthenticationService(Microsoft.JSInterop.IJSRuntime jsRuntime, Microsoft.Extensions.Options.IOptions<Microsoft.AspNetCore.Components.WebAssembly.Authentication.RemoteAuthenticationOptions<TProviderOptions>> options, Microsoft.AspNetCore.Components.NavigationManager navigation, Microsoft.AspNetCore.Components.WebAssembly.Authentication.AccountClaimsPrincipalFactory<TAccount> accountClaimsPrincipalFactory) -> void
*REMOVED*~Microsoft.AspNetCore.Components.WebAssembly.Authentication.RemoteAuthenticationService<TRemoteAuthenticationState, TAccount, TProviderOptions>.RemoteAuthenticationService(Microsoft.JSInterop.IJSRuntime jsRuntime, Microsoft.Extensions.Options.IOptions<Microsoft.AspNetCore.Components.WebAssembly.Authentication.RemoteAuthenticationOptions<TProviderOptions>> options, Microsoft.AspNetCore.Components.NavigationManager navigation, Microsoft.AspNetCore.Components.WebAssembly.Authentication.AccountClaimsPrincipalFactory<TAccount> accountClaimsPrincipalFactory) -> void
~Microsoft.AspNetCore.Components.WebAssembly.Authentication.RemoteAuthenticationState.ExtraQueryParameters.get -> System.Collections.Generic.Dictionary<string, string>
~Microsoft.AspNetCore.Components.WebAssembly.Authentication.RemoteAuthenticationState.ExtraQueryParameters.set -> void
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Web;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.AspNetCore.Components.Rendering;
using Microsoft.AspNetCore.Components.WebAssembly.Authentication.Internal;
Expand Down Expand Up @@ -218,6 +221,8 @@ protected override async Task OnParametersSetAsync()
private async Task ProcessLogIn(string returnUrl)
{
AuthenticationState.ReturnUrl = returnUrl;
AuthenticationState.ExtraQueryParameters = GetParameters();

var result = await AuthenticationService.SignInAsync(new RemoteAuthenticationContext<TAuthenticationState>
{
State = AuthenticationState
Expand Down Expand Up @@ -331,6 +336,13 @@ private async Task ProcessLogOutCallback()
}
}

private Dictionary<string, string> GetParameters()
{
var queryString = new Uri(Navigation.Uri).Query;
var parameters = HttpUtility.ParseQueryString(queryString);
return parameters.AllKeys.ToDictionary(k => k, k => parameters[k]);
}

private string GetReturnUrl(TAuthenticationState state, string defaultReturnUrl = null)
{
if (state?.ReturnUrl != null)
Expand Down