以下のコードを淡色のアクティブディレクトリ認証に使用しました。このメソッドが存在しないことを示すauthContext.AcquireTokenByAuthorizationCodeで失敗します。私がそれを確認しようとしたとき、バージョン3.1のdllでそれを示しています。 authContext.AcquireTokenByAuthorizationCodeAsyncメソッドがあります。このコードを変更して起動時と同じように非同期にすることはできません。この問題を非同期に変換するための提案authContext.AcquireTokenByAuthorizationCodeは最新のSystem.IdentityModel.Clients.ActiveDirectoryと連携していません
public partial class Startup
{
public void Configuration(IAppBuilder app)
{
ConfigureAuth(app);
}
}
public void ConfigureAuth(IAppBuilder app)
{
ApplicationDbContext db = new ApplicationDbContext();
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
app.UseCookieAuthentication(new CookieAuthenticationOptions());
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);
return Task.FromResult(0);
}
}
});
}
[ADAL .NET Ref Doc](https://docs.microsoft.com/en-us/active-directory/adal/microsoft.identitymodel.clients.activedirectory)を参考にしてください。 –