Skip to content

Instantly share code, notes, and snippets.

@venkatmarepalli
Last active June 22, 2017 05:56
Show Gist options
  • Select an option

  • Save venkatmarepalli/b0bb6fe9f59b56a964e9136aafe75c67 to your computer and use it in GitHub Desktop.

Select an option

Save venkatmarepalli/b0bb6fe9f59b56a964e9136aafe75c67 to your computer and use it in GitHub Desktop.
Curl to retrieve refresh token and access tokens
#Initial url opening login page with below parameters
#Once this is logged in it will redirect to the redirect uri with code in query params.
https://login.microsoftonline.com/{tenent-Id}/oauth2/authorize?nonce=258db3ce0f&state=87da5fbdd4d2785fd52b2&redirect_uri=http://xyz.com/getauthcode.html&response_type=code&client_id=30a3a6f4-138b..&scope=openid+email+profile&access_type=offline
#To retrieve access token using Authorization code
#Token end point https://login.windows.net/{tenant_id}/oauth2/token also works
curl -X POST -H "Cache-Control: no-cache" -H "Content-Type: application/x-www-form-urlencoded" -d "code=AQABAAIAAABnfi&client_id=12456&grant_type=authorization_code&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2F" 'https://login.microsoftonline.com/common/oauth2/v2.0/token'
#The below Curl without client_secret works only for Native apps created on Azure AD. For Web App client_secret is mandatory.
#This will retrieve new access token and refresh token.
curl -X POST -H "Cache-Control: no-cache" -H "Content-Type: application/x-www-form-urlencoded" -d "client_id=123456&refresh_token=dlfldfdklfdfsADS2sd&grant_type=refresh_token&client_secret=" 'https://login.microsoftonline.com/common/oauth2/v2.0/token'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment