How to easily get an authentication token to your Office 365 Tenant

I have been developing a backend service that requires a Microsoft Graph token passed up from the frontend. During this development, I have been using Postman to do the call, and have used a simple SPA with authentication to give me a token to my development tenant.

This has been a pretty annoying way to do things when the token expires every half an hour or so, meaning I need to generate another.

Fortunately, early on in my development, I listened to an episode of the Microsoft 365 Developer podcast, in which Jeremey Thake almost in passing mentioned how to get a token for your tenant from the Microsoft Graph Explorer.

Now I use the Graph Explorer a lot, but I had no idea about this awesome feature.

All you need to do is:

  • In your favourite browser, go to the Microsoft Graph Explorer
  • Sign-in to your tenant. This is important, as you can’t get the token via the dummy tenant they use for demo content.
  • Open the F12 developer tools
  • Type tokenPlease() and hit Enter
It’s that easy!

This has blown me away.

Now the token you get back is based on the permission scopes you have consented to the Graph Explorer, but the token is not application-specific and you are perfectly able to use this token, with the same permission scopes, in your own app. Keep in mind this only is available to your user in the tenant you have signed in to.

One last cool thing is the Graph Explorer refreshed the token for you, so there is no need to sign in every time you want the token.

Comments are closed.

Blog at WordPress.com.

Up ↑

%d bloggers like this: