多个Blazor Server应用程序和Azure身份验证注销问题

时间:2019-10-24 13:14:31

标签: c# blazor asp.net-core-3.0 blazor-server-side

我有2个Blazor服务器端应用程序,每个应用程序在Azure AD中都有自己的应用程序注册。从VS2019 .NET Core 3.0中创建新的Blazor服务器端应用程序开始,它们几乎是开箱即用的。

在浏览器的2个选项卡中打开它们并且我注销后,App AI仍能够导航App B中的页面链接。AppB在按下浏览器的页面刷新按钮之前看不到我已注销

我尝试将@attribute [Authorize]添加到页面,在App.razor页面中定义<NotAuthorized>,然后使用页面AuthenticationStateProvider函数中的OnInitializedAsync检查{ {1}},没有运气。

.IsAuthenticated
@page "/fetchdata"
@attribute [Authorize]    

[CascadingParameter] Task<AuthenticationState> authenticationStateTask { get; set; }

    protected override async Task OnInitializedAsync()
    {
        var authState = await authenticationStateTask;
        var user = authState.User;
        if (!user.Identity.IsAuthenticated)
        {
            NavigationManager.NavigateTo("Error");
        }
    }
<Router AppAssembly="@typeof(Program).Assembly">
    <Found Context="routeData">
        <AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)">
            <NotAuthorized>
                <h1>Please Log In.</h1>
            </NotAuthorized>
        </AuthorizeRouteView>
    </Found>
    <NotFound>
        <CascadingAuthenticationState>
            <LayoutView Layout="@typeof(MainLayout)">
                <p>Sorry, there's nothing at this address.</p>
            </LayoutView>
        </CascadingAuthenticationState>
    </NotFound>
</Router>

1 个答案:

答案 0 :(得分:0)

这可能与诸如Chrome和Firefox的Web浏览器对其Cookie的SameSite实施进行重大更改有关。

您可以尝试此处描述的缓解措施: https://github.com/aspnet/AspNetCore/issues/14996