我使用以下代码进行 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/