Visual Studio 2017 で標準の ASP.NET MVC AAD 認証済みアプリケーションを作成しました。次のものが含まれています。
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);
}
}
});
しばらくの間、ブラウザーに表示され、IIS Express 用に Visual Studio で構成されたとおりにHttpContext.Current.Request.Url
戻ります。https://localhost:44345/
しかし、しばらくすると、http://127.0.0.1/
代わりに戻り始めます。これにより、AzureAD 認証はローカルホストの開発 URL ではなく運用 URL を返します。
開発用 URL をハード コードすることもできますが、どこにデプロイしても機能するように動的にする必要があります。
開発ボックスhttp://127.0.0.1/
ではなくIIS Express が戻ってくるのはなぜですか? https://localhost:44345/
また、正しい値を返すにはどうすればよいですか。
`