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

时间:2017-10-10 07:22:03

标签: c# azure-active-directory adal

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);

1 个答案:

答案 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);
}

如果您还有问题,请检查并随时告诉我。