Microsoft.IdentityModel.Clients.ActiveDirectory v3.17.0 和 appid/appsecret

Microsoft.IdentityModel.Clients.ActiveDirectory v3.17.0 and appid/appsecret

Microsoft.IdentityModel.Clients.ActiveDirectory 的 v3.16.1 升级到 v3.17.0 时,我找不到关于如何使用带有 clientIdclientSecret 的 ADAL 应用获取访问令牌的过载我以前可以作为 ClientCredential 对象传入。

下面的 AcquireTokenAsync 重载已不存在,那么未来的方法是什么?

var clientCredential = new ADAL.ClientCredential(AppId, AppSecret);
var token = await authenticationContext.AcquireTokenAsync(GraphResourceId, clientCredential);

AcquireTokenAsync 在 class 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);
}

请检查一下,如果仍有问题,请随时告诉我。