如何在Azure Web Apps中将redirect_uri协议设置为HTTPS [英] How to set redirect_uri protocol to HTTPS in Azure Web Apps

查看:141
本文介绍了如何在Azure Web Apps中将redirect_uri协议设置为HTTPS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正面临以下问题.我有一个要部署到Azure的ASP Net Core 2 Web应用程序.应用程序身份验证与Azure Active Directory集成在一起,因此,当我尝试登录时,会发生以下请求:

I am facing the following problem. I have an ASP Net Core 2 web app that I want to deploy to Azure. The app authentication is integrated with the Azure Active Directory, so when I try to login the following requests happen:

GET https://login.microsoftonline.com/ecf3f643-27e5-4aa7-9d56-fd350e1e9c37/oauth2/authorize?client_id=20a2bcb5-0433-4bb4-bba3-d7dc4c533e85&redirect_uri=http://myapplication.mydomain.com/account/signin [...]  200 OK
POST http://myapplication.mydomain.com/account/signin 301 Redirect --> https://myapplication.mydomain.com/account/signin
GET https://myapplication.mydomain.com/account/signin 500 Internal Server Error

第一个GET是普通的Azure Active Directory登录请求. 请注意,redirect_uri参数的协议为http .

The first GET is the normal Azure Active Directory login request. Notice the redirect_uri parameter has protocol http.

第二个请求是重定向到redirect_uri,这是带有某些参数的POST.由于我已将Azure配置为仅允许HTTPS通信,因此IIS使用HTTPS重定向到相同的URL.这是第三个请求.请注意,这第三个请求是GET请求,因为 HTTP重定向始终是GET请求 POST请求的所有参数均丢失,并且身份验证失败,从而在后端给出HTTP 500错误.

The second request is the redirection to the redirect_uri, a POST with some parameters. Since I have configured Azure to allow only HTTPS traffic, then IIS redirects to the same URL with HTTPS. That's the third request. Notice this third request is a GET request, since HTTP redirection is always a GET request all the paremeters of the POST request are lost, and the authentication fails giving a HTTP 500 error in the backend.

我尝试将redirect_uri参数中的协议手动更改为HTTPS,并且它可以正常运行.因此,我唯一需要做的就是让ASP Net Core知道该协议是HTTPS .

I have tried to manually change the protocol in the redirect_uri parameter manually to HTTPS, and it works as expected. So, the only thing I need is to make ASP Net Core aware that the protocol is HTTPS.

那怎么办?我在Internet上搜索了成千上万的网页,但没有明确的答案.

How can that be done? I've searched tons of pages in the Internet without a clear answer.

注意:redirect_uri由Kestrel设置.由于Azure应用服务将IIS放在我的Kestrel前面并在那里进行SSL终止,因此Kestrel和我的应用不知道该协议是HTTPS,因此在重定向uri中使用HTTP.

Note: the redirect_uri is set by Kestrel. Since Azure App Service puts an IIS in front of my Kestrel and does the SSL termination there, Kestrel and my app do not know the protocol is HTTPS, and therefore use HTTP in the redirect uri.

更新1

按照 @Bruce 的建议,我尝试了示例

Following the advice of @Bruce I've tried the example here, cloning the repository and configuring the application and the AD as stated there, and I am able to reproduce the error.

重定向URI继续使用http协议.如果仅在AD应用程序配置中添加https终结点作为回复URL,则会收到错误The reply address 'http://testloginad.azurewebsites.net/signin-oidc' does not match the reply addresses configured for the application.如果将http协议端点添加为回复URL,则会收到HTTP 500错误,如下所示:

The redirect URI continues to be with http protocol. If I only add in the AD app configuration the https endpoint as reply URL, I get the error The reply address 'http://testloginad.azurewebsites.net/signin-oidc' does not match the reply addresses configured for the application. If I add the http protocol endpoint as reply URL, then I get an HTTP 500 error like the following:

System.Exception: Correlation failed.
   at Microsoft.AspNetCore.Authentication.RemoteAuthenticationHandler`1.<HandleRequestAsync>d__12.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.<Invoke>d__6.MoveNext()

我仍在思考问题与Kestrel有关,因为它不知道通过HTTPS正在建立连接,但是我不知道如何将信息传递给它.

I am still thinking the problem is related to Kestrel not knowing the connection is being done through HTTPS, but I do not know how to convey that information to it.

更新2

我使用的Azure Web应用程序的配置:

The configuration of the Azure web app I used:

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆