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 #25391

Closed
umlaufa1 opened this issue Aug 29, 2020 · 13 comments
Closed

Support for extraQueryParameters in Blazor WASM / MSAL #25391

umlaufa1 opened this issue Aug 29, 2020 · 13 comments
Assignees
Labels
affected-few This issue impacts only small number of customers area-blazor Includes: Blazor, Razor Components enhancement This issue represents an ask for new feature or an enhancement to an existing one feature-blazor-wasm This issue is related to and / or impacts Blazor WebAssembly feature-blazor-wasm-auth help wanted Up for grabs. We would accept a PR to help resolve this issue severity-major This label is used by an internal tool
Milestone

Comments

@umlaufa1
Copy link

Issue
I would like to pass a query parameter to a B2C user flow when authenticating my Blazor client app. The query parameter could be used, for example, to change the content on the login screen or lots of other useful things

B2C supports this through their IdentityExperienceFramework. Specifically, you can add the following to your user flow:

<InputClaims>
        <InputClaim ClaimTypeReferenceId="QueryParamName" />
</InputClaims>

MSAL also supports extra parameters using the "extraQueryParameters" type in AuthenticationParameters (https://docs.microsoft.com/en-us/azure/active-directory/develop/msal-js-pass-custom-state-authentication-request)

It appears WASM.Authentication.Msal does not provide access to extraQueryParameters.

Solution I'd like to see
Ideally, I would like the following behavior:

  1. A user goes to http://www.myblazorapp.com/customID
  2. CustomID is extracted from URL.
  3. CustomID passed to my B2C user flow as a query parameter. (This doesn't appear to be supported)
  4. My B2C user flow uses the CustomID.

Other Info
I think I could achieve a similar result with a"loginHint" but WASM.Authentication.Msal doesn't appear to support this either. The use of extraQueryParameters would provide the most flexibility. I have not been able to find any interim solution that lets me pass custom state info from my blazer app to a b2c userflow (I hope I am not missing something obvious :- ) )

@mkArtakMSFT mkArtakMSFT added area-blazor Includes: Blazor, Razor Components feature-blazor-wasm This issue is related to and / or impacts Blazor WebAssembly enhancement This issue represents an ask for new feature or an enhancement to an existing one labels Aug 30, 2020
@mkArtakMSFT mkArtakMSFT added this to the Backlog milestone Aug 31, 2020
@ghost
Copy link

ghost commented Aug 31, 2020

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

@mkArtakMSFT mkArtakMSFT added the feature-blazor-msal This issue is related to MSAL usage in Blazor label Aug 31, 2020
@captainsafia captainsafia added the help wanted Up for grabs. We would accept a PR to help resolve this issue label Sep 9, 2020
@captainsafia captainsafia added affected-few This issue impacts only small number of customers severity-major This label is used by an internal tool labels Oct 5, 2020
@johnnybegood
Copy link

The extra query parameters are also needed when calling an API that requires interaction: https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-conditional-access-dev-guide#scenario-app-performing-the-on-behalf-of-flow.

@miguelhasse
Copy link

This is also essential to allow the use of "id-token-hint"
Azure Active Directory B2C | Pass an ID token hint

@matt-goldman
Copy link

Any chance of an update on this? I've worked on three Blazor projects now where we've had to come up with ugly workarounds. I know this might seem minor, but adding this would bring so much joy to so many people's lives! (Well, mine. But I'm sure others too.)

@RMcD
Copy link

RMcD commented Aug 31, 2022

Does #42580 cover this with it's Dynamic/Extensible approach?

@danroth27
Copy link
Member

@javiercn Should this be closed as done as part of #42580?

@iXyles
Copy link

iXyles commented Oct 4, 2022

Hey @danroth27,

From my testing today, the #42580 does not resolve the issue of adding "custom" parameters.
My understanding by looking at the examples from that feature this should work:

var request = new InteractiveRequestOptions { Interaction = InteractionType.SignIn, ReturnUrl = Navigation.Uri };
request.TryAddAdditionalParameter("random", "value");

But the "random" parameter does not get added to the authentication.
However, the samples @javiercn did was with prompt which works just fine, as it is a regular OAuth parameter. Please feel free to correct me if I am wrong here, but seems like something is still missing to support extraQueryParameters dynamically.

Edit: On a side note, if I would instead do

request.TryAddAdditionalParameter("extraQueryParams", "value");

It would end up write the string value into the request but split up by array indexes, see image for reference;
image

@danroth27
Copy link
Member

@iXyles There were some known issues with dynamic authentication requests and MSAL in .NET 7 RC1. Can you try again with .NET 7 RC2, which was recently released?

@iXyles
Copy link

iXyles commented Oct 12, 2022

@danroth27 Did a quick test, and the issue is still persistent sadly. Extra query parameters are split up similarly to what I showed above, and custom parameters are not included in the request sent to the IDP.

@javiercn
Copy link
Member

@iXyles the code needs to be something like this:

var extraQueryParametersDictionary = new Dictionary<string, string>
{
    ["brand_color"] = "red"
};
request.TryAddAdditionalParameter("extraQueryParameters", JsonSerializer.Deserialize<JsonElement>(JsonSerializer.Serialize(extraQueryParametersDictionary)));

@iXyles
Copy link

iXyles commented Oct 14, 2022

@javiercn sadly this did not work, the parameter does not get passed when I am testing it locally with RC2.

Image for reference of what I tested with:
image

@javiercn
Copy link
Member

@iXyles this issue is for Azure AD B2C, which uses MSAL.JS.

In your case you seem to be using a different provider, which uses oidc-client.js. The parameter name there is extraQueryParams

@iXyles
Copy link

iXyles commented Oct 15, 2022

@javiercn Ah right... Forgot that little detail. Thanks for noticing that and cheers for showing a solution to the issue! :)

@ghost ghost locked as resolved and limited conversation to collaborators Nov 14, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affected-few This issue impacts only small number of customers area-blazor Includes: Blazor, Razor Components enhancement This issue represents an ask for new feature or an enhancement to an existing one feature-blazor-wasm This issue is related to and / or impacts Blazor WebAssembly feature-blazor-wasm-auth help wanted Up for grabs. We would accept a PR to help resolve this issue severity-major This label is used by an internal tool
Projects
None yet
Development

No branches or pull requests

10 participants