androidazurekotlinsharepointmicrosoft-graph-api

Getting two acces tokens using single login prompt for sharpoint api and graph api


I would like to ask if there is a way to get two tokens using a single prompt for SharePoint and Graph API using Kotlin. I have managed to get one for Graph API but haven't had luck with the SharePoint one. I always get a "non-existing scope" error for SharePoint if I try to mix the scopes.

Suggestion appreciated as I am a rookie


Solution

  • Note that, you cannot mix scopes and get two access tokens using single login prompt. You need to make 2 separate login prompts with different scope values to generate tokens.

    I registered one Azure AD application and added API permissions for both Microsoft Graph and SharePoint as below:

    enter image description here

    To get access token for Microsoft Graph, pass scope parameter value as "https://graph.microsoft.com/.default" that generates token with below aud & scp claims after successful authentication:

    enter image description here

    Similarly, pass "https://tenantname.sharepoint.com/.default" as scope parameter value to generate token for SharePoint API that gives below claims when you decode it:

    enter image description here

    Like this, you need to get access tokens for Microsoft Graph and SharePoint APIs with 2 separate login prompts by passing different scopes without mixing it.