简体   繁体   English

无法进行身份验证 - 带有 Azure Active Directory (OpenIdConnect) 的 Azure Web 应用

[英]Unable Authenticate - Azure web app with Azure Active Directory (OpenIdConnect)

I have created a web app in azure and i am using Azure AD authentication (OpenID-Connect) to authenticate my web app.我在 azure 中创建了一个 web 应用程序,我正在使用 Azure AD 身份验证 (OpenID-Connect) 来验证我的 web 应用程序。 but i couldn't authenticate web app in few machines.但我无法在几台机器上验证 Web 应用程序。

In some machines it(AAD authentication) working in google chrome, not in IE,Edge, Firefox.在某些机器上,它(AAD 身份验证)在谷歌浏览器中工作,而不是在 IE、Edge、Firefox 中工作。 few times its worked in all the browsers.几次它在所有浏览器中都有效。

I have failed in below steps我在以下步骤中失败了

  1. Removed all the cookies and claims删除了所有 cookie 和声明
  2. Clear the session and tested in private mode清除会话并在私有模式下测试

In Startup.cs在 Startup.cs 中

public void ConfigureAuth(IAppBuilder app)
{
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);

app.UseCookieAuthentication(new CookieAuthenticationOptions());

app.UseOpenIdConnectAuthentication(
                new OpenIdConnectAuthenticationOptions
                {
                    ClientId = Config.ClientId,
                    ClientSecret = Config.ClientSecret,
                    Authority = Config.Authority,
                    PostLogoutRedirectUri = Config.PostLogoutRedirectUri, 
                    RedirectUri = Config.PostLogoutRedirectUri,  
                    Notifications = new OpenIdConnectAuthenticationNotifications()
                    { 
                    }
                });
}

When i tried to login with Azure AAD.当我尝试使用 Azure AAD 登录时。 i received error message like 'We couldn't sign you in. Please try again.'我收到类似“我们无法让您登录。请重试”的错误消息。

info:信息:

No error Log in browser console没有错误 登录浏览器控制台

URL : ** https://login.microsoftonline.com/TENANTID/oauth2/authorize?client_id=CLIENTID&redirect_uri=URL&response_mode=form_post&response_type=code%20id_token&scope=openid%20profile&state=OpenIdConnect.AuthenticationProperties%3TOKEN&x-client-SKU=ID_NET461&x-client-ver=5.5.0.0 ** URL :** https://login.microsoftonline.com/TENANTID/oauth2/authorize?client_id=CLIENTID&redirect_uri=URL&response_mode=form_post&response_type=code%20id_token&scope=openid%20profile&state=OpenIdConnect.AuthenticationProperties%3TOKEN&x-client4-client-SKU=版本=5.5.0.0 **

Enabled the azure authentication/authorization启用azure身份验证/授权

Issue: working in google chrome, not in IE, Edge, Firefox, Safari.问题:在谷歌浏览器中工作,而不是在 IE、Edge、Firefox、Safari 中工作。 few times it worked in all the browsers.几次它在所有浏览器中都有效。

HOW TO RESOLVE THIS ISSUE: The problem has been fixed in ASP.NET core.如何解决此问题:该问题已在 ASP.NET 核心中修复。 To resolve this issue, you can upgrade your application to use ASP.NET Core.要解决此问题,您可以升级应用程序以使用 ASP.NET Core。 If you must continually stay on ASP.NET, perform the following: Update your application's Microsoft.Owin.Host.SystemWeb package be at least version and Modify your code to use one of the new cookie manager classes, for example something like the following:如果您必须继续使用 ASP.NET,请执行以下操作: 将您的应用程序的 Microsoft.Owin.Host.SystemWeb 包更新为至少版本并修改您的代码以使用新的 cookie 管理器类之一,例如如下所示:

app.UseCookieAuthentication(new CookieAuthenticationOptions 
{ 
    AuthenticationType = "Cookies", 
    CookieManager = new Microsoft.Owin.Host.SystemWeb.SystemWebChunkingCookieManager() 
});

Reference Link 参考链接

After some research, I found that you need to use HTTPS and also write this piece of code under de Startup.cs file:经过一番研究,发现需要使用HTTPS ,还要在de Startup.cs文件下写这段代码:

using Microsoft.Owin.Host.SystemWeb;


public void ConfigureAuth(IAppBuilder app)
{
    app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);

    app.UseCookieAuthentication(new CookieAuthenticationOptions {
                CookieManager = new SystemWebCookieManager()
    });
...

If you are using Azure App, follow these steps to force the application to always use https:如果您使用的是 Azure 应用程序,请按照以下步骤强制应用程序始终使用 https:

  1. Log in to the Azure portal.登录到 Azure 门户。

  2. Navigate to App Services.导航到应用服务。

  3. Click on the reported App.单击报告的应用程序。

  4. Under Setting section, Click on 'TLS/SSL settings'.在设置部分下,单击“TLS/SSL 设置”。

  5. In 'Protocol Settings', Set 'HTTPS Only' to 'On'.在“协议设置”中,将“仅 HTTPS”设置为“开”。

I ran into the same error message.我遇到了同样的错误消息。 But in my case I saw in the console a lot of calls on my app's /signin-oidc (302's).但就我而言,我在控制台中看到我的应用程序的 /signin-oidc(302's)有很多调用。

The problem was that I removed the following line from the ConfigureServices method:问题是我从 ConfigureServices 方法中删除了以下行:

services.Configure<CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });

After replacing it all worked fine.更换后一切正常。

HTH, J. HTH,J。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 验证 Azure 活动目录 - Authenticate Azure Active Directory Visual Studio 2017 WebTest使用Azure Active Directory(AAD)对Azure Web App进行身份验证 - Visual Studio 2017 WebTest authenticate Azure Web App with Azure Active Directory (AAD) 无法使用 EFCore 使用 Azure Active Directory 对 SQL 服务器进行身份验证 - Unable to authenticate SQL Server with Azure Active Directory using EFCore 生成访问令牌以验证 Azure 活动目录应用程序 - Generate access token to authenticate Azure Active directory App OpenIdConnect是唯一在Azure Active Directory中实现授权的中间件吗 - Is OpenIdConnect the only middleware that implements authorization in Azure Active Directory 在将Azure Active Directory dotnetcore Webapp实施到WebAPI OpenIDConnect时出错 - Getting error implementing azure active directory dotnetcore webapp to webapi openidconnect 将Meteor与Azure Web App一起使用Azure Active Directory - Using Azure Active Directory on Azure Web App with Meteor 使用Azure Active Directory和Azure移动服务验证PHP Web应用程序 - Authenticating a PHP Web App with Azure Active Directory and Azure Mobile Services 使用Azure Active Directory验证ASP.NET Core 2.1 Web API和使用Entity Framework验证Azure SQL - Authenticate ASP.NET Core 2.1 Web API with Azure Active Directory and Azure SQL with Entity Framework 如何使用Azure Active Directory中的凭据进行身份验证? - How to Authenticate using credentials in Azure Active Directory?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM