【问题标题】: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
【问题描述】:

我正在尝试使用已为 Microsoft 图形资源生成的访问令牌获取 SharePoint 在线网站集的访问令牌,并使用 Pnp AuthManger 传递该访问令牌以获取网站集的客户端上下文。

谁能建议我如何做到这一点?是否可行?

我知道一个事实可以对不同的资源组进行两次不同的身份验证调用。

在下面的文章中找到,但它接缝了 Microsoft.IdentityModel.Clients.ActiveDirectory 中的 AuthenticationContext 类已更新,不再具有 AuthenticationContext.AcquireTokenByRefreshTokenAsync 方法。

http://blogs.perficient.com/microsoft/2016/08/getting-access-tokens-for-both-sharepoint-and-microsoft-graph/

注意:我在上面使用 .net 库。

【问题讨论】:

    标签: 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));
    

    调用该方法时,它会检查令牌缓存。如果是不存在访问令牌(或访问令牌已过期)的差异资源,它将使用刷新令牌(如果存在且未过期)来获取该资源的新访问令牌。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-08-05
      • 1970-01-01
      • 2017-08-31
      • 2022-01-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多