admin管理员组文章数量:1419202
I have a normal Blazor app, with the default boilerplate user/password authentication from MS. I have 2 users, root and test.
I logged in with root and clicked remember me. Then I logout and log in again with free, and initiated a payment process. The flow navigates to an outside page (different domain), and then calling a callback on succes back to may app/domain.
The problem is that now, I am logged in as root instead of free.
Is there a way to fix/prevent this?
I have a normal Blazor app, with the default boilerplate user/password authentication from MS. I have 2 users, root and test.
I logged in with root and clicked remember me. Then I logout and log in again with free, and initiated a payment process. The flow navigates to an outside page (different domain), and then calling a callback on succes back to may app/domain.
The problem is that now, I am logged in as root instead of free.
Is there a way to fix/prevent this?
Share Improve this question edited Jan 30 at 7:50 Tiny Wang 16.5k2 gold badges18 silver badges38 bronze badges asked Jan 29 at 13:53 AndreiMAndreiM 8861 gold badge11 silver badges20 bronze badges 1 |1 Answer
Reset to default 0I had a test with a .Net 6 blazor server application and an 6 MVC application. You mentioned with the default boilerplate user/password authentication from MS
so that the blazor server app I created via VS chose "Microsoft identity platfor" as the authentication type.
My test uses codes below. The blazor app will redirect to my MVC app, and in my MVC controller action it will return Redirect("https://localhost:7100/");
to mock the payment callback.
@page "/"
@inject IJSRuntime jsRuntime
@inject NavigationManager NavManager
<PageTitle>Index</PageTitle>
<h1>Hello, world!</h1>
Welcome to your new app.
<SurveyPrompt Title="How is Blazor working for you?" />
<button onclick="@direct">direct with NavigationManager to external site</button>
<button onclick="@direct2">direct with js invoke to external site</button>
@code{
public void direct()
{
NavManager.NavigateTo("https://localhost:7037/home/DynamicContent");
}
public async Task direct2()
{
await jsRuntime.InvokeAsync<object>("open", "https://localhost:7037/home/DynamicContent", "_blank");
}
}
Everything worked well, I signed in with my account and choose Stay signed in
,
then I click sign out button in my site, it will redirect to Microsoft Identity platform sign out page and guide me to choose my account to sign out, and it will finally redirct to /MicrosoftIdentity/Account/SignedOut
. Then I go back to my blazor site and click to navigate to MVC page, it can still redirct back without any signed-in account.
We could deduce that the issue might relate to the persistent authentication cookies stored in the browser when using the "Remember Me" option. And if we used official Microsoft Identity SDK, I trust it will help handle the cookie automatically. If you are working on OpenIdConnect + Azure AD configuration, I'm afraid you need to deal with the cookie manually, and you might need codes similart to
await SignInManager.SignOutAsync();
HttpContext.Response.Cookies.Delete(".AspNetCore.Identity.Application");
本文标签: netBlazor external callback is logging a different userStack Overflow
版权声明:本文标题:.net - Blazor: external callback is logging a different user - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745293621a2651946.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
root
is now the user. Did you use AuthenticationStateProvider ? UsedAuthorizeView
to display the name? – Panagiotis Kanavos Commented Jan 29 at 14:16