簡體   English   中英

使用 microsoft/azure 登錄 Asp.net WebAPP 在 chrome 中不起作用

[英]Asp.net WebAPP login with microsoft/azure doesn't work in chrome

我目前正在嘗試設置“mircosoft 登錄” - 使用 Azure 進行身份驗證。 我已經下載了示例項目並按照教程( https://docs.microsoft.com/de-de/azure/active-directory/develop/quickstart-v2-aspnet-core-webapp#how-the-sample-作品

我還將 .net 核心版本從 2 升級到 3.1 並進行了一些更改以使其運行(不是最好的代碼,我只是將其用作參考)但是登錄確實適用於 Microsoft Edge 和 Firefox 但是不是鉻。 如果我嘗試使用 Chrome,我會收到以下錯誤:

An unhandled exception occurred while processing the request.
Exception: Correlation failed.
Unknown location

Exception: An error was encountered while handling the remote login.
Microsoft.AspNetCore.Authentication.RemoteAuthenticationHandler<TOptions>.HandleRequestAsync()

我的 Startup.cs 看起來像這樣:

using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.AzureAD.UI;
using Microsoft.AspNetCore.Authentication.OAuth.Claims;
using Microsoft.AspNetCore.Authentication.OpenIdConnect;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Authorization;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System.Security.Claims;
using Microsoft.AspNetCore.HttpOverrides;

namespace WebApp_OpenIDConnect_DotNet
{
    public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public IConfiguration Configuration { get; }

        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure<CookiePolicyOptions>(options =>
            {
                 options.CheckConsentNeeded = context => true;
                 options.MinimumSameSitePolicy = SameSiteMode.None;
            });

            services.AddAuthentication(AzureADDefaults.AuthenticationScheme)
                .AddAzureAD(options => Configuration.Bind("AzureAd", options));

            services.Configure<OpenIdConnectOptions>(AzureADDefaults.OpenIdScheme, options =>
            {
                options.Authority = options.Authority + "/v2.0/";
                options.TokenValidationParameters.ValidateIssuer = false;
            });

            services.AddMvc(options =>
            {
                var policy = new AuthorizationPolicyBuilder()
                    .RequireAuthenticatedUser()
                    .Build();
                options.Filters.Add(new AuthorizeFilter(policy));
            })
            .SetCompatibilityVersion(CompatibilityVersion.Version_3_0);
        }


        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                app.UseHsts();
            }
            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseCookiePolicy();
            app.UseRouting();
            app.UseAuthentication();
            app.UseAuthorization();
            app.UseEndpoints(routes =>
            {
                routes.MapControllerRoute(
                    "default",
                    "{controller=Home}/{action=Index}/{id?}");
                routes.MapRazorPages();
            });
        }
    }
}

我不認為我在配置上犯了錯誤,因為它適用於 Edge 和 Firefox,但我不確定為什么這不適用於 chrome。 我錯過了什么嗎? Chrome 版本:版本 85.0.4183.102(官方版本)(64 位)

提前致謝

這個問題已由@Christoph Lütjen 的評論解決,將其添加為結束問題的答案:

如果您使用http而不是https 進行測試,請禁用以下設置:

  1. 轉到chrome://flags/
  2. 使用“SameSite”過濾
  3. 禁用所有標志
  4. 刷新瀏覽器

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM