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

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

Closed
juho-hanhimaki opened this issue Nov 2, 2022 · 13 comments
Assignees
Labels
area-blazor Includes: Blazor, Razor Components feature-blazor-msal This issue is related to MSAL usage in Blazor feature-blazor-wasm This issue is related to and / or impacts Blazor WebAssembly feature-blazor-wasm-auth investigate Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update.

Comments

@juho-hanhimaki
Copy link
Contributor

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

@dotnet-issue-labeler
Copy link

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.

@ghost ghost added the untriaged label Nov 2, 2022
@juho-hanhimaki
Copy link
Contributor Author

Wrong repo, perhaps somebody can transfer to aspnetcore?

@MihaZupan MihaZupan transferred this issue from dotnet/runtime Nov 2, 2022
@TanayParikh TanayParikh added area-blazor Includes: Blazor, Razor Components feature-blazor-wasm This issue is related to and / or impacts Blazor WebAssembly feature-blazor-msal This issue is related to MSAL usage in Blazor feature-blazor-wasm-auth and removed untriaged labels Nov 2, 2022
@juho-hanhimaki
Copy link
Contributor Author

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
Copy link
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.

@TanayParikh TanayParikh added this to the 7.0.x milestone Nov 7, 2022
@TanayParikh
Copy link
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?

@juho-hanhimaki
Copy link
Contributor Author

Fyi, seeing this issue still on published release builds on 7.0.0 release.

@javiercn
Copy link
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
Copy link
Member

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

@javiercn
Copy link
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>

@javiercn javiercn added the Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. label Nov 11, 2022
@ghost
Copy link

ghost commented Nov 11, 2022

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
Copy link
Contributor Author

@javiercn that does solve the problem.

@ghost ghost added Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update. and removed Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. labels Nov 11, 2022
@javiercn
Copy link
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
Copy link
Member

this was addressed in 7.0.1 as part of #45028

@ghost ghost locked as resolved and limited conversation to collaborators Jan 14, 2023
@dougbu dougbu removed this from the 7.0.x milestone Jan 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components feature-blazor-msal This issue is related to MSAL usage in Blazor feature-blazor-wasm This issue is related to and / or impacts Blazor WebAssembly feature-blazor-wasm-auth investigate Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update.
Projects
None yet
Development

No branches or pull requests

5 participants