我正在处理 adal 到 msal 的迁移,在更新记录时面临问题,Web 应用程序正在获取上次登录的用户详细信息来更新数据。请在下面找到我的代码。
公共异步任务 GetTokenForWebApiAsync( 字符串资源Id2, 字符串权威) { IConfidentialClientApplication 应用程序 = this.CreateApplication(); 身份验证结果 authResult;
var scopes = new[] { $"{resourceId2}/.default" };
////var account = await app.GetAccountAsync().ConfigureAwait(false);
var authres = OpenIdAuthenticationEvents.AuthenticationResult;
try
{
// try to get an already cached token
authResult = await app.AcquireTokenSilent(
scopes, authres.Account)
.ExecuteAsync().ConfigureAwait(false);
}
catch (MsalUiRequiredException)
{
// The controller will need to challenge the user
// including asking for claims={ex.Claims}
throw;
}
return authResult;
}