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

尚恩

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

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

我尝试将@attribute [Authorize]添加到页面,<NotAuthorized>在App.razor页面中定义,并使用AuthenticationStateProviderin页面OnInitializedAsync功能检查是否.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>
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddAuthentication(AzureADDefaults.AuthenticationScheme).AddAzureAD(options => Configuration.Bind("AzureAd", options));
            services.AddControllersWithViews(options =>
            {
                var policy = new AuthorizationPolicyBuilder().RequireAuthenticatedUser().Build();
                options.Filters.Add(new AuthorizeFilter(policy));
            });
            services.AddRazorPages();
            services.AddServerSideBlazor();
            services.AddSingleton<WeatherForecastService>();
            services.AddServerSideBlazor().AddCircuitOptions(options => { options.DetailedErrors = true; });
            services.AddSingleton<TestContextService>();
        }
迈克尔·华盛顿

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

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

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何让 Blazor 应用程序查看本地 SQL Server 以进行身份验证?

多个Django应用程序,共享身份验证

多个 .NET 应用程序共享身份验证

使用多个应用程序处理 django 身份验证

在闪亮的应用程序和多个页面中进行身份验证

在多个应用程序上进行SSO和REST Api身份验证

使用NGINX反向代理后面的docker + kubernetes在带有Identity Server 4的Blazor Server应用程序中添加身份验证和授权

用户在 Blazor Webassembly 身份验证和授权中具有多个角色时的问题?

使用不同AuthenticationProviders多个WebSecurityConfigurerAdapter(用于API和LDAP的web应用程序基本身份验证)

适用于同时登录多个应用程序的AppEngine的OpenID Connect和移动身份验证选项

从Blazor应用程序中的Middleware类获取经过身份验证的用户

如何在 Blazor B2C 应用程序启动期间禁用身份验证?

如何在Blazor应用程序中仅对经过身份验证的用户响应图像数据?

在为托管的Blazor WebAssembly应用程序提供服务之前,如何使用Azure AD B2C对服务器上的用户进行身份验证?

用于多个应用程序的OWIN身份验证服务器

使用 Xero 的 Java SDK 来支持多个私有应用程序的身份验证?

对耳内的多个Web应用程序使用一种身份验证

使用 Blazor 服务器和 Azure AD 身份验证获取身份验证令牌

多个问题再次使用Google Endpoints Identity-Aware代理对GCP上托管的B2B应用程序的G Suite用户进行身份验证

Blazor 应用程序中的 EditForm 有多个提交按钮

部署的WebAssembly Blazor应用程序无法正确路由身份验证,但可以在本地运行

如何在 blazor 服务器端应用程序中扩展身份验证过程?

从多个应用程序注销

在 Back4App 项目中,多个应用程序(不同平台)可以访问相同的数据库和身份验证吗?

如何在多个 Symfony 应用程序(相同的数据库,多个内核)之间共享身份验证?

如何在Blazor WASM中为多个身份提供者实现外部身份验证?

Azure API应用程序登录和身份验证

使用Auth0通过单个应用程序登录针对多个资源进行身份验证

Blazor 表单上多个组件的绑定和验证