无法通过Azure AD进行身份验证,丢失cookie并重定向未显示任何权限

问题描述 投票:0回答:1

坦白地说,确实是一场噩梦。

我有https://github.com/Azure-Samples/active-directory-aspnetcore-webapp-openidconnect-v2/tree/master/1-WebApp-OIDC的存储库,该存储库应使用ASP Core 3.0设置Azure AD和开放ID。

我正在使用Azure来使用ASP Core 3.0 MVC部署应用程序。我已经在解决方案中实现了上述仓库,该仓库应该处理startup.cs中的所有内容,我的本地主机工作正常。

启动与1-WebApp-OIDC解决方案相同(除了日志和与DI相关的注册之外。

该应用已在Azure门户中注册,租户ID和客户端ID很好,正确的重定向也在那里。App Service Auth也被关闭(我读到这可能是一个问题,因为许多人已经通过关闭它来解决了这个问题)。同样,首页,索引控制器具有[Authorize]属性。

现在,关于部署,我一直在努力;您无权查看此目录或页面。’在我的/ signin-oidc重定向网址上。请注意,即使不使用openidconnect类库,我也会收到此消息。

如果我转到https://mysite.azurewebsites.net/.auth/login/aad/callback-我得到“您已成功登录”页面,并带有“返回网站”链接。单击后,返回与上述相同的消息。

[我也从https://mysite.azurewebsites.net/.auth.me获得了令牌-阅读了.NET Core app with Azure App Service Authentication,但他能够通过登录并且没有获得正确的声明标识。

现在..当我在域登录时签入Azure时,它显示为成功。然后,我登录Kudu来检查(... /应用程序中)有矛盾的日志。

诊断日志说:

2020-02-01 10:32:19.279 +00:00 [Debug] Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware: Request did not match any endpoints
2020-02-01 10:32:19.279 +00:00 [Debug] Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationHandler: AuthenticationScheme: AzureADCookie was not authenticated.

为每个会话生成向导的另一组日志显示:

2020-02-01T10:32:01  PID[3780] Verbose     Received request: GET https://mysite.azurewebsites.net/
2020-02-01T10:32:01  PID[3780] Information Redirecting: https://login.windows.net/89f3808f-0cff-4297-b17a-313007c7b8a6/oauth2/authorize?response_type=id_token&redirect_uri=https%3A%2F%2Fmysite.azurewebsites.net%2F.auth%2Flogin%2Faad%2Fcallback&client_id=f70bd4d6-3cb3-463e-9fca-974053e2f177&scope=openid+profile+email&response_mode=form_post&nonce=6f1c5c8d07f5481193439dd95c3cf03b_20200201103701&state=redir%3D%252F
2020-02-01T10:32:02  PID[3780] Verbose     Received request: POST https://mysite.azurewebsites.net/.auth/login/aad/callback
2020-02-01T10:32:02  PID[3780] Verbose     JWT validation succeeded. Subject: 'C6JYPu8NBYT8sC-s6G33w6sxNkct28RdeeyfL1SndjA', Issuer: 'https://sts.windows.net/89f3808f-0cff-4297-b17a-313007c7b8a6/'.
2020-02-01T10:32:02  PID[3780] Information Login completed for '[email protected]'. Provider: 'aad'.
2020-02-01T10:32:02  PID[3780] Verbose     Writing 'AppServiceAuthSession' cookie for site 'mysite.azurewebsites.net'. Length: 920.
2020-02-01T10:32:02  PID[3780] Information Redirecting: https://mysite.azurewebsites.net/
2020-02-01T10:32:02  PID[3780] Verbose     Received request: GET https://mysite.azurewebsites.net/
2020-02-01T10:32:02  PID[3780] Verbose     Found 'AppServiceAuthSession' cookie for site 'mysite.azurewebsites.net'. Length: 920.
2020-02-01T10:32:02  PID[3780] Verbose     Authenticated [email protected] successfully using 'Session Cookie' authentication.
2020-02-01T10:32:19  PID[3780] Verbose     Received request: POST https://mysite.azurewebsites.net/signin-oidc
2020-02-01T10:32:19  PID[3780] Verbose     Found 'AppServiceAuthSession' cookie for site 'mysite.azurewebsites.net'. Length: 920.
2020-02-01T10:32:19  PID[3780] Information Sending response: 403.60 Forbidden
2020-02-01T10:32:19  PID[3780] Warning     Cross-site request forgery detected for user '[email protected]' from referer 'login.microsoftonline.com'!
2020-02-01T10:32:19  PID[3780] Verbose     Received request: GET https://mysite.azurewebsites.net/favicon.ico
2020-02-01T10:32:19  PID[3780] Verbose     Found 'AppServiceAuthSession' cookie for site 'mysite.azurewebsites.net'. Length: 920.
2020-02-01T10:32:19  PID[3780] Verbose     Authenticated [email protected] successfully using 'Session Cookie' authentication.

很明显,cookie丢失了,我已经读到了一个重定向循环,它会干扰核心的cookie和开放ID的cookie。我已经用尽了堆栈溢出和其他所有文章,无济于事。

[存在一个非常相似但使用Google Auth的问题-Requesting refresh token fails.No refresh tokens were found in the token store。这不适用于AAD。

我真的做不完,我已经坚持了很长时间,如果再花一天时间,我可能会发疯。我敢肯定这不会很难😅。

任何帮助或指导将不胜感激。

azure asp.net-core azure-active-directory openid
1个回答
0
投票
显然很有趣,哈哈...

这实际上与Azure AD或OpenId完全无关。

这是我的数据层中的数据库调用,正在我的家庭控制器(而不是Azure中)中调用外部数据库,这引发了所有这些问题。

© www.soinside.com 2019 - 2024. All rights reserved.