2

我在 Visual Studio 2017 中创建了一个普通的 ASP.NET MVC AAD Authenticated 应用程序。它包括以下内容:

app.UseOpenIdConnectAuthentication(
                new OpenIdConnectAuthenticationOptions
                {
                    ClientId = clientId,
                    Authority = Authority,
                    PostLogoutRedirectUri = postLogoutRedirectUri,

                    Notifications = new OpenIdConnectAuthenticationNotifications()
                    {
                        // If there is a code in the OpenID Connect response, redeem it for an access token and refresh token, and store those away.
                        AuthorizationCodeReceived = (context) =>
                        {
                            var code = context.Code;
                            ClientCredential credential = new ClientCredential(clientId, appKey);
                            string signedInUserID = context.AuthenticationTicket.Identity.FindFirst(ClaimTypes.NameIdentifier).Value;
                            AuthenticationContext authContext = new AuthenticationContext(Authority, new ADALTokenCache(signedInUserID));
                            AuthenticationResult result = authContext.AcquireTokenByAuthorizationCode(
                            code, new Uri(HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Path)), credential, graphResourceId);
                            var graphUri = new Uri(AAD_GRAPH_URI);
                            var serviceRoot = new Uri(graphUri, tenantId);
                            this.aadClient = new ActiveDirectoryClient(serviceRoot, async () => await AcquireGraphAPIAccessToken(AAD_GRAPH_URI, authContext, credential));
                            return Task.FromResult(0);
                        }
                    }
});

一会儿HttpContext.Current.Request.Url返回https://localhost:44345/浏览器中列出的内容,并在 Visual Studio for IIS Express 中进行配置。

然而,过了一会儿,它开始返回http://127.0.0.1/这会导致 AzureAD 身份验证返回生产 URL,而不是 localhost 开发 URL。

我可以对开发 URL 进行硬编码,但它应该是动态的,这样它就可以在我部署它的任何地方工作。

为什么 IIS Express 返回http://127.0.0.1/而不是https://localhost:44345/在我的开发框中?以及如何让它返回正确的值。 `

4

0 回答 0