How to access id_token in MSGraph SDK on iOS?

derpoliuk

I'm using MSGraph SDK iOS to login users with their Office365 accounts.

My end goal is to get:

Using sample app I was able to login user, get a refresh token and user details (via [[[[MSGraphClient client] me] request] getWithCompletion:...]) but I can't find id_token anywhere.

Also, the Android version of the app I'm working on is using https://outlook.office.com/api/v2.0 as a base URL for SDK and I'm trying to change it also in iOS app from https://graph.microsoft.com/v1.0/.

I might be missing something obvious or important in docs or sample app, sorry if that's the case.

Question is: how to get id_token in MSGraphSDK on iOS?

UPD:

Here's code I'm using:

[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 doesn't have any property that can be connected with id_token. The question is how to get id_token from NXOAuth2Client or MSGraphSDK frameworks?

Marc LaFleur

An id_token is only returned if you're using the OpenID Connect flow. To enable this, you need to add openid to the list of scopes you're requesting and id_token+code as your response-type.

Optionally you can also request email and profile if you want to get a more "complete" id_token.

One additional item to keep in mind, the tokens are not provided by the SDK. They are obtained from Azure Active Directory via OAuth. The SDK simply takes the token you've previously obtained.

You can obtain a token using just about any library that supports OAuth 2.0 but I suspect the sample you're looking at is using NXOAuth2AuthenticationProvider. Something along the lines of:

[NXOAuth2AuthenticationProvider setClientId:<clientId>
    scopes:@[@"https://graph.microsoft.com/Files.ReadWrite",
    @"https://graph.microsoft.com/Calendars.ReadWrite"]];

In order to obtain the id_token using the above example, you add the openid scope:

[NXOAuth2AuthenticationProvider setClientId:<clientId>
    scopes:@[@"https://graph.microsoft.com/Files.ReadWrite",
    @"https://graph.microsoft.com/Calendars.ReadWrite",
    @"openid"]];

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Oath2 open Id connect - How to exchange access_token for a id_token

How to "sign in with Google" (id_token) *and* receive a code/access_token for specific scope (for the backend)

How get in Azure access_token from Azure Function app with id_token?

How to add roles claim in access_token , currently it is coming in id_token?

Oauth 2.0 | SPA | How does id_token disguise as an access_token for accessing restricted web resources?

How i can add the calculated fields to access_token / id_token

Dropbox Core SDK for iOS using access token

How to update user profile photo with msgraph-sdk-java?

How to add a member to a directory role using the msgraph-sdk-java

Msgraph-sdk-java vs Msgraph-sdk-android for Android?

API Gateway Authorizer Accepts ID_token But Not Access_Token

Getting xmpp_login Access Token Not Working in Facebook iOS SDK

Salesforce Native IOS SDK can't refresh access token

Swift version of Facebook iOS SDK and how to access data in Response

Quickblox: how to access custom object special parameters (increment) in iOS SDK?

Should we refresh Token when using UsernamePasswordCredential with msgraph-sdk-java

How to go from https://github.com/microsoftgraph/MSGraph-SDK-Code-Generator to code (java)

PHP: How do I get a list of emails from Outlook using msgraph-sdk-php?

access_token same as id_token when trying to acquire access token with ADAL.js AuthenticationContext?

Generating Reply Email via MSGraph PHP SDK

msgraph-sdk-python not returning any data

How to retrieve access-token from GCP Golang SDK?

how to use graph api access token in php for facebook sdk

How to get the access token from Google Sign-In Javascript SDK?

Facebook PHP SDK - how to get a long lived page access token

How to Access Token for Dropbox SDK and Facebook API in same application

How to Get Access Token Using LinkedIn API JavaScript SDK

How to I access Security token for Python SDK boto3

How to get facebook access token with Facebook Android SDK 3.8?