从Microsoft.IdentityModel.Clients.ActiveDirectory
的v3.16.1升级到v3.17.0时,我找不到如何使用我之前使用clientId
和clientSecret
的ADAL应用获取访问令牌的重载可以作为ClientCredential
对象传入。
以下AcquireTokenAsync
的重载不再存在,那么这种方法将会是什么呢?
var clientCredential = new ADAL.ClientCredential(AppId, AppSecret);
var token = await authenticationContext.AcquireTokenAsync(GraphResourceId, clientCredential);
答案 0 :(得分:1)
AcquireTokenAsync
位于班级AuthenticationContextConfidentialClientExtensions
中且仍可使用。请参阅以下代码(source code):
/// <summary>
/// Acquires security token from the authority.
/// </summary>
/// <param name="ctx">Authentication context instance</param>
/// <param name="resource">Identifier of the target resource that is the recipient of the requested token.</param>
/// <param name="clientCredential">The client credential to use for token acquisition.</param>
/// <returns>It contains Access Token and the Access Token's expiration time. Refresh Token property will be null for this overload.</returns>
public static async Task<AuthenticationResult> AcquireTokenAsync(this AuthenticationContext ctx,
string resource, ClientCredential clientCredential)
{
return await ctx.AcquireTokenForClientCommonAsync(resource, new ClientKey(clientCredential))
.ConfigureAwait(false);
}
如果您还有问题,请检查并随时告诉我。