Search code examples
microsoft-graph-apiadal

getting the "adal.access.token.key|https://graph.microsoft.com"" from the session (sessionStorage)


Trying to figure out the access-token for graph call I found this article: https://piasys.com/blog/getting-an-access-token-for-a-service-in-spfx/ That Shows how to get it with:

this.aadTokenProvider = await this.context.aadTokenProviderFactory.getTokenProvider(); this.aadTokenProvider.getToken(“https://graph.microsoft.com”); But when I do JSON.stringify(sessionStorage) at the console, I see it at the end of the JSON Is there a way to parse the sessionStorage to get the token without all the async /await hoops? Thanks


Solution

  • The token is put into sessionStorage by the auth libraries as a result of those async/await calls. Could you read the item out of storage and use it, you could, for a while, but those calls ensure you will always get a fresh unexpired token.

    Paolo's point with the blog post is not to encourage you to go read from session storage but to use the async/await calls because you will always get a current token