title: To get refreshtoken, accesstoken in Microsoft Graph API
body: <p>I am trying to generate credentials (AccessToken, RefreshToken) in Microsoft Graph API. Successfully generated AccessToken by following <a href="https://docs.microsoft.com/en-us/graph/use-postman" rel="nofollow noreferrer">this Documentation</a>. But I am struggling with the way to get a refresh token.</p>
  <p>Steps:</p>
  <ul>
  <li><p><em>App Registration is done in Azure Active Directory.</em></p>
  <p><a href="https://i.stack.imgur.com/jUNTd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jUNTd.png" alt="App Registration" /></a></p>
  </li>
  <li><p><em>Client Secret also got</em></p>
  <p><a href="https://i.stack.imgur.com/HB4zY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HB4zY.png" alt="Client Secret" /></a></p>
  </li>
  <li><p><em>List of API Permission Given</em></p>
  <p><a href="https://i.stack.imgur.com/Inx5I.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Inx5I.png" alt="API Permission" /></a></p>
  </li>
  </ul>
  <p>As per <a href="https://docs.microsoft.com/en-us/graph/auth-v2-user" rel="nofollow noreferrer">this Documentation</a>, I followed the remaining steps to generate credentials.</p>
  <ul>
  <li><em>Below mentioned Authorization Request pasted in google URL and got code value as well.</em></li>
  </ul>
  <p><strong>Request</strong>:</p>
  <pre><code>https://login.microsoftonline.com/common/oauth2/v2.0/authorize
    ?client_id=14edf196-xxxxxx
    &amp;response_type=code
    &amp;redirect_uri=https://oauth.pstmn.io/v1/browser-callback 
    &amp;response_mode=query
    &amp;scope=offline_access%20Mail.Read%20Mail.ReadBasic%20Mail.ReadWrite%20Mail.Read.Shared%20Mail.ReadWrite.Shared%20Mail.Send%20Mail.Send.Shared%20MailboxSettings.Read%20MailboxSettings.ReadWrite%20IMAP.AccessAsUser.All%20POP.AccessAsUser.All%20SMTP.Send%20Files.Read%20Files.Read.All%20Files.ReadWrite%20Files.ReadWrite.All%20Files.ReadWrite.AppFolder%20Files.Read.Selected%20Files.ReadWrite.Selected%20User.Read%20User.ReadWrite%20User.ReadBasic.All%20User.Read.All%20User.ReadWrite.All%20User.Invite.All%20User.Export.All%20User.ManageIdentities.All
    &amp;state=12345
  </code></pre>
  <p><strong>Code value:</strong></p>
  <pre><code>0.ASUAYH3m5fSttECIPDUdwv7vTpbx7RSNwIhCtEISG2GkwQwlAMQ.AQABAAIAAADxxxxxxxxxxxxxxxxx
  </code></pre>
  <ul>
  <li><p>Next step is to get AccessToken, for this POST request made in Postman which gives AccessToken in Response</p>
  <p><a href="https://i.stack.imgur.com/KaUHO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KaUHO.png" alt="AccessToken Generation" /></a></p>
  <p>Note: When i remove scope in above request, accesstoken received, otherwise i got ERROR Respose like</p>
  <blockquote>
  <p>&quot;error: invalid_grant Description:AADSTS70008: The provided authorization code or refresh token has expired due to inactivity. Send a new interactive authorization request for this user and resource.\r\nTrace ID: 98e82735-4764-496a-881b-9b78faf3f000\r\nCorrelation ID: 3d4a78b2-5a26-47af-ae14-cbb82c12a9ae\r\nTimestamp: 2021-06-14 12:57:01Z&quot;</p>
  </blockquote>
  </li>
  </ul>
  <p>As per OAuth2.0, i hope no need to pass scope while generating accesstoken.</p>
  <p><strong>Response</strong>:</p>
  <pre><code>{
      &quot;token_type&quot;: &quot;Bearer&quot;,
      &quot;scope&quot;: &quot;email openid profile https://graph.microsoft.com/Files.Read https://graph.microsoft.com/Files.Read.All https://graph.microsoft.com/Files.Read.Selected https://graph.microsoft.com/Files.ReadWrite https://graph.microsoft.com/Files.ReadWrite.All https://graph.microsoft.com/Files.ReadWrite.AppFolder https://graph.microsoft.com/Files.ReadWrite.Selected https://graph.microsoft.com/IMAP.AccessAsUser.All https://graph.microsoft.com/Mail.Read https://graph.microsoft.com/Mail.Read.Shared https://graph.microsoft.com/Mail.ReadBasic https://graph.microsoft.com/Mail.ReadWrite https://graph.microsoft.com/Mail.ReadWrite.Shared https://graph.microsoft.com/Mail.Send https://graph.microsoft.com/Mail.Send.Shared https://graph.microsoft.com/MailboxSettings.Read https://graph.microsoft.com/MailboxSettings.ReadWrite https://graph.microsoft.com/POP.AccessAsUser.All https://graph.microsoft.com/SMTP.Send https://graph.microsoft.com/User.Export.All https://graph.microsoft.com/User.Invite.All https://graph.microsoft.com/User.ManageIdentities.All https://graph.microsoft.com/User.Read https://graph.microsoft.com/User.Read.All https://graph.microsoft.com/User.ReadBasic.All https://graph.microsoft.com/User.ReadWrite https://graph.microsoft.com/User.ReadWrite.All&quot;,
      &quot;expires_in&quot;: 3599,
      &quot;ext_expires_in&quot;: 3599,
      &quot;access_token&quot;: &quot;eyJ0eXAiOiJKV1QiLCJubxxxxxxxxxxxxx&quot;
  }
  </code></pre>
  <p>If you seen in above json response comes from postman, refresh token is missing.</p>
  <p>This refresh token is required while integrating MS Outlook operation in WSO2 EI by following <a href="https://docs.wso2.com/display/ESBCONNECTORS/Configuring+Outlook+Mail+Operations" rel="nofollow noreferrer">this</a></p>
  <p>Kindly help me to get this. or what is the step that i missed?</p>