Skip to main content

Office 365: Refresh Token

Register App

Following are the steps to register App,

  1. Sign in to Azure portal with the email address having permission to perform the action to be automated. The permission details are mentioned under the specific step documentation.
  2. For the automation of email handling actions, Sign in to the Azure portal with the email address that is going to be used in the step.
  3. Select the Azure Active Directory.
  4. Select App registrations.
  5. Select New registration.
  6. Name the application. Select a supported account type, which determines who can use the application.
  7. Under Redirect URI, select Web for the type of application you want to create. For example, https://automationedge.com.
  8. Select Register.

  1. After creating app, click on Redirect URIs.

  1. Check the checkbox provided in below screen shot and click on save

Provide API Permission

  1. Click on API Permission.
  2. Click on Add Permission.
  3. Click on Microsoft Graph.
  4. Provide all required permissions.

tip

Delegated Offline_access permission is mandatory to generate the refresh token.


Creating Client Secret

  1. Click on Certificates and secrets.
  2. Click on New client secret.
  3. Enter Description.
  4. Select the Expires value.

  1. Copy and save the value with you as it visible only for one time.

How to generate Refresh Token URL and Run in Browser

  1. Create Below URL and run in browser. https://login.microsoftonline.com/Tenant_id/oauth2/v2.0/authorize?client_id=value&scope=Permissions &response_type=code. Example: https://login.microsoftonline.com/2f906216-6aaa-4ee5-8c13-5bbb3af06089/oauth2/v2.0/authorize?client_id=e6080cc9-dccc-4e8b-a22e-93174e01459b&scope=Mail.Read Mail.ReadWrite Mail.Send openid User.Read offline_access &response_type=code

  2. After running in the browser the below login screen will appear, log in with the user who has created the app.


  1. After login below screen will appear, on below screen click on Accept Button.

  1. After clicking on accept button you will redirect to URI provided during app creation, once you are redirected you will get the code in address bar as shown in below screen shot.

  1. In below image highlighted is the sample code to be fetched from URL.

  1. Once you get the code you need to create a POST request in postman to generate the refresh token. Below are the details

POST
URL: https://login.microsoftonline.com/{Tenant id}/oauth2/v2.0/token

Headers:
Content-Type: application/x-www-form-urlencoded Body: x-www-form-urlencoded(key value pair) client_id={client_id} client_secret={ client_secret } code={code} grant_type=authorization_code

Postman Request:


Postman Response: