【问题标题】:Get SharePoint Access token from already generated access token for the Microsoft Graph resource (https://graph.microsoft.com)从已为 Microsoft Graph 资源 (https://graph.microsoft.com) 生成的访问令牌中获取 SharePoint 访问令牌
【发布时间】:2018-02-06 23:36:53
【问题描述】:
【问题讨论】:
标签:
c#
azure-active-directory
adal
【解决方案1】:
ADAL 支持获取多种资源的令牌。您仍然可以使用 ADAL 库来实现您的需求。
是的,在 ADAL 3 中,AcquireTokenByRefreshToken 方法不存在。但是刷新令牌仍然存在于令牌缓存中,您实际上不需要使用您自己的应用代码中的刷新令牌。使用 ADAL 3,当您想获取不同资源的访问令牌时,可以使用 AcquireTokenSilentAsync 方法:
string userObjectID = ClaimsPrincipal.Current.FindFirst("http://schemas.microsoft.com/identity/claims/objectidentifier").Value;
AuthenticationContext authContext = new AuthenticationContext(Startup.Authority, new NaiveSessionCache(userObjectID));
ClientCredential credential = new ClientCredential(clientId, appKey);
result = await authContext.AcquireTokenSilentAsync(YourResource, credential, new UserIdentifier(userObjectID, UserIdentifierType.UniqueId));
调用该方法时,它会检查令牌缓存。如果是不存在访问令牌(或访问令牌已过期)的差异资源,它将使用刷新令牌(如果存在且未过期)来获取该资源的新访问令牌。