首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在id_token上访问MSGraph SDK中的MSGraph?

如何在id_token上访问MSGraph SDK中的MSGraph?
EN

Stack Overflow用户
提问于 2018-03-26 20:28:57
回答 1查看 271关注 0票数 1

我使用MSGraph SDK iOS登录用户的Office365帐户。

我的最终目标是:

使用示例应用程序,我能够登录用户,获得刷新令牌和用户详细信息(通过[[[[MSGraphClient client] me] request] getWithCompletion:...]),但我在任何地方都找不到id_token

另外,我正在开发的安卓版本的应用程序正在使用https://outlook.office.com/api/v2.0作为SDK的基本URL,我也试图在iOS应用程序中从https://graph.microsoft.com/v1.0/中修改它。

在文档或示例应用程序中,我可能遗漏了一些显而易见或重要的东西,如果是这样的话,我很抱歉。

的问题是:如何使id_tokenMSGraphSDK on iOS?

UPD:

下面是我使用的代码:

代码语言:javascript
复制
[NXOAuth2AuthenticationProvider setClientId:<clientId> scopes:@[@"https://graph.microsoft.com/Files.ReadWrite", @"https://graph.microsoft.com/Calendars.ReadWrite", @"openid"]];
[[NXOAuth2AuthenticationProvider sharedAuthProvider] loginWithViewController:nil completion:^(NSError *error) {
    if (error) {
        return;
    }
    NSArray *accounts = [[NXOAuth2AccountStore sharedStore] accountsWithAccountType:@"MSGraph"];
    NXOAuth2Account *account = accounts.firstObject;
}];

NXOAuth2Account没有任何可以与id_token连接的属性。问题是如何从NXOAuth2ClientMSGraphSDK框架中获取MSGraphSDK

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-03-26 20:36:00

只有在使用id_token流时才返回OpenID连接。要启用此功能,需要将openid添加到您请求的作用域列表中,并将id_token+code添加为您的response-type

如果您希望获得一个更“完整”的email,也可以选择请求profileid_token

需要记住的另一个项目是,SDK没有提供令牌。它们是通过OAuth从Azure Active Directory获得的。SDK只接受您以前获得的令牌。

您可以使用几乎任何支持OAuth 2.0的库获得令牌,但我怀疑您正在查看的示例是使用NXOAuth2AuthenticationProvider。与…有关的东西:

代码语言:javascript
复制
[NXOAuth2AuthenticationProvider setClientId:<clientId>
    scopes:@[@"https://graph.microsoft.com/Files.ReadWrite",
    @"https://graph.microsoft.com/Calendars.ReadWrite"]];

为了使用上面的示例获得id_token,可以添加openid作用域:

代码语言:javascript
复制
[NXOAuth2AuthenticationProvider setClientId:<clientId>
    scopes:@[@"https://graph.microsoft.com/Files.ReadWrite",
    @"https://graph.microsoft.com/Calendars.ReadWrite",
    @"openid"]];
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49500076

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档