我将以下代码用于Azure活动目录身份验证。它在authContext.AcquireTokenByAuthorizationCode失败,说明此方法不存在。当我尝试验证它是否显示在3.1版dll中时。有authContext.AcquireTokenByAuthorizationCodeAsync方法。我无法在启动时修改此代码以使其异步。关于此的任何建议转换为异步
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 v2到ADAL v3,有许多重大更改。您这里最快的解决方案可能就是简单地使用旧版本的ADAL,您可以从Nuget here下载该版本。
否则,您可以查看我们现有的样本,这些样本已迁移到ADAL v3 here。
关于c# - authContext.AcquireTokenByAuthorizationCode不适用于最新的System.IdentityModel.Clients.ActiveDirectory,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42607230/