Skip to content

Blazor WebAssembly Msal TryAddAdditionalParameter("prompt", "select_account") does nothing #44854

Closed
@juho-hanhimaki

Description

@juho-hanhimaki

Description

I am using the MSAL authentication with Azure AD trying to add prompt parameter to the sign in. It does not work as expected.

The observed request https://login.microsoftonline.com/common/oauth2/v2.0/authorize?... doesn't contain the prompt parameter and the request just completes with SSO.

Reproduction Steps

RedirectToLoginSelectAccount.razor

@using Microsoft.AspNetCore.Components.WebAssembly.Authentication;
@inject NavigationManager Navigation

@code {
    protected override void OnInitialized()
    {
        var requestOptions = new InteractiveRequestOptions()
            {
                Interaction = InteractionType.SignIn,
                ReturnUrl = Navigation.Uri,
            };

        requestOptions.TryAddAdditionalParameter("prompt", "select_account");

        Navigation.NavigateToLogin("authentication/login", requestOptions);
    }
}

The following weird version works on development build in VS, but doesn't work in published release build.

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

Expected behavior

Authentication to include the prompt parameter.

Actual behavior

Prompt parameter missing.

Regression?

No response

Known Workarounds

No response

Configuration

7.0.101 [C:\Program Files\dotnet\sdk]

<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="7.0.0-rtm.22512.1" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="7.0.0-rtm.22512.1" PrivateAssets="all" />
<PackageReference Include="Microsoft.Authentication.WebAssembly.Msal" Version="7.0.0-rtm.22512.1" />
<PackageReference Include="Microsoft.Extensions.Http" Version="7.0.0-rtm.22511.4" />

Other information

No response

Activity

ghost

ghost commented on Nov 2, 2022

@ghost

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

juho-hanhimaki

juho-hanhimaki commented on Nov 2, 2022

@juho-hanhimaki
ContributorAuthor

Wrong repo, perhaps somebody can transfer to aspnetcore?

transferred this issue fromdotnet/runtimeon Nov 2, 2022
juho-hanhimaki

juho-hanhimaki commented on Nov 3, 2022

@juho-hanhimaki
ContributorAuthor

I am pretty sure this is a bug. Hopefully someone can take a look and reproduce. I don't think I am able to test using the newer rtm.22513.3 packages as they complain about downgrades from 7.0.0 (which isn't out yet).

#42580

https://learn.microsoft.com/en-us/aspnet/core/blazor/security/webassembly/additional-scenarios?view=aspnetcore-7.0#customize-the-login-process

TanayParikh

TanayParikh commented on Nov 3, 2022

@TanayParikh
Contributor

We're also using that workaround in the test code:

["CoolName"] = JsonSerializer.Deserialize<JsonElement>(JsonSerializer.Serialize("Alfred"))

This appears to be a known issue, @javiercn do you have a tracking issue for this, or is the workaround (also mentioned here) the recommended resolution for now? Note for the workaround, @juho-hanhimaki mentioned:

The following weird version works on development build in VS, but doesn't work in published release build.

added this to the 7.0.x milestone on Nov 7, 2022
TanayParikh

TanayParikh commented on Nov 10, 2022

@TanayParikh
Contributor

@javiercn just to confirm the next steps here, were there any changes made following the community standup which may not have flowed through / may not have been comprehensive? Or are we just initially investigating?

1 remaining item

javiercn

javiercn commented on Nov 10, 2022

@javiercn
Member

@TanayParikh this is worth investigating.

There are some issues I think with the way we do Json serialization internally and some linking related issues.

javiercn

javiercn commented on Nov 11, 2022

@javiercn
Member

I believe this is likely caused by the same issue as #44973

javiercn

javiercn commented on Nov 11, 2022

@javiercn
Member

@juho-hanhimaki try disabling linking for this assembly

Add this to your csproj

<ItemGroup>
  <TrimmerRootDescriptor Include="TrimmerRootDescriptor.xml" />
</ItemGroup>

And this is TrimmerRootDescriptor.xml:

<?xml version="1.0" encoding="UTF-8" ?>
<linker>
	<assembly fullname="Microsoft.Authentication.WebAssembly.Msal" preserve="all" />
	<assembly fullname="Microsoft.AspNetCore.Components.WebAssembly.Authentication" preserve="all" />
</linker>
added
Needs: Author FeedbackThe author of this issue needs to respond in order for us to continue investigating this issue.
on Nov 11, 2022
ghost

ghost commented on Nov 11, 2022

@ghost

Hi @juho-hanhimaki. We have added the "Needs: Author Feedback" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

juho-hanhimaki

juho-hanhimaki commented on Nov 11, 2022

@juho-hanhimaki
ContributorAuthor

@javiercn that does solve the problem.

ghost added
Needs: Attention 👋This issue needs the attention of a contributor, typically because the OP has provided an update.
on Nov 11, 2022
ghost removed
Needs: Author FeedbackThe author of this issue needs to respond in order for us to continue investigating this issue.
on Nov 11, 2022
javiercn

javiercn commented on Nov 11, 2022

@javiercn
Member

@juho-hanhimaki thanks for the confirmation.

This looks very much like the same issue then. Hopefully we can get a fix into the next patch.

javiercn

javiercn commented on Dec 15, 2022

@javiercn
Member

this was addressed in 7.0.1 as part of #45028

ghost locked as resolved and limited conversation to collaborators on Jan 14, 2023
removed this from the 7.0.x milestone on Jan 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Needs: Attention 👋This issue needs the attention of a contributor, typically because the OP has provided an update.area-blazorIncludes: Blazor, Razor Componentsfeature-blazor-msalThis issue is related to MSAL usage in Blazorfeature-blazor-wasmThis issue is related to and / or impacts Blazor WebAssemblyfeature-blazor-wasm-authinvestigate

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @dougbu@javiercn@juho-hanhimaki@TanayParikh@mkArtakMSFT

      Issue actions

        Blazor WebAssembly Msal TryAddAdditionalParameter("prompt", "select_account") does nothing · Issue #44854 · dotnet/aspnetcore