用ASP.NET核心MVC双重身份验证

发布于 2025-01-23 10:03:48 字数 1446 浏览 0 评论 0原文

我有一个ASP.NET Core MVC Web应用程序,我想允许用户使用Identity Server 4和Azure Active Directory进行身份验证。我所有的内部用户(公司用户)都需要使用Azure AD,所有外部用户都应使用身份服务器进行签名。

I have setup authentication in startup class as follows:

 services.AddAuthentication(options =>
            {
                options.DefaultScheme = OpenIdConnectDefaults.AuthenticationScheme;
            })
             .AddOpenIdConnect("oidc",  options =>
             {
                 options.Authority = Configuration["Identity:WebApiUrl"];
    
                 options.ClientId = "xxxxxxx";
                 options.ClientSecret = "xxxxxxxxx";
                 options.ResponseType = "id_token";
    
                 options.Scope.Add("openid");
                 options.Scope.Add("profile");
    
                 options.GetClaimsFromUserInfoEndpoint = true;
                 options.ClaimActions.MapUniqueJsonKey("email", "email");
    
                 options.SaveTokens = true;
             })
             .AddMicrosoftIdentityWebApp(Configuration.GetSection("AzureAd"));

This will only allow internal users to signin using azure AD and external users gets following error.

异常:相关失败。
未知位置

例外:处理远程登录时遇到错误。

microsoft.aspnetcore.authentication.remoteauthenticationhandler.handlerequestasync()

How can I solve this issue and allow both external and internal users to login ?

谢谢。

I have an ASP.NET Core MVC web application and I want to allow my users to authenticate using identity server 4 and Azure Active Directory. All my internal users (company users) need to use Azure AD and all external users should use identity server to signing.

I have setup authentication in startup class as follows:

 services.AddAuthentication(options =>
            {
                options.DefaultScheme = OpenIdConnectDefaults.AuthenticationScheme;
            })
             .AddOpenIdConnect("oidc",  options =>
             {
                 options.Authority = Configuration["Identity:WebApiUrl"];
    
                 options.ClientId = "xxxxxxx";
                 options.ClientSecret = "xxxxxxxxx";
                 options.ResponseType = "id_token";
    
                 options.Scope.Add("openid");
                 options.Scope.Add("profile");
    
                 options.GetClaimsFromUserInfoEndpoint = true;
                 options.ClaimActions.MapUniqueJsonKey("email", "email");
    
                 options.SaveTokens = true;
             })
             .AddMicrosoftIdentityWebApp(Configuration.GetSection("AzureAd"));

This will only allow internal users to signin using azure AD and external users gets following error.

Exception: Correlation failed.
Unknown location

Exception: An error was encountered while handling the remote login.

Microsoft.AspNetCore.Authentication.RemoteAuthenticationHandler.HandleRequestAsync()

How can I solve this issue and allow both external and internal users to login ?

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文