Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using ADFS OAuth Refresh Token

I have ADFS3 OAuth2 configured to return Refresh Tokens:

PS> Set-AdfsRelyingPartyTrust -TargetName "RPT Name" -IssueOAuthRefreshTokensTo AllDevices
PS> Set-AdfsRelyingPartyTrust -TargetName "RPT Name" -TokenLifetime 10
PS> Set-AdfsProperties -SSOLifetime 480

Here the Access Token lasts for 10 minutes and the Refresh Token lasts for 480 minutes.

I then generate an Access Token by GETing:

https://myadfsdomain/adfs/oauth/authorize
    ?response_type=code
    &client_id=MYCLIENTID
    &redirect_uri=https://myserver/callback
    &resource=MYRelyingPartyId

and POSTing the responseCode Eg:

$http({method: "post", 
       headers: {'Content-Type': 'application/x-www-form-urlencoded'}, 
       url: "https://myadfsdomain/adfs/oauth2/token", 
       data: "client_id=MYCLIENTID&code=" + responseCode + "&redirect_uri=https://myserver/callback&grant_type=authorization_code"  })

The response has the Access Token, type, Expire Time and Refresh Token:

{"access_token":"blah...",
 "token_type":"bearer",
 "expires_in":600,
 "refresh_token":"blahblah..."}

Great. The Access Token is now valid for however long it has been configured for (10 minutes here)

Questions is, once that time has expired, how do we use the refresh_token to get another Access Token? IE:

  • What is the URL?
  • Do we POST?
  • What param names do we use to POST the refresh_token?
like image 869
Daniel Flippance Avatar asked Mar 09 '23 22:03

Daniel Flippance


1 Answers

The refresh token grant type is also executed against the token endpoint that you used to exchange the Authorization Code at. You should use POST according to the RFC: https://www.rfc-editor.org/rfc/rfc6749#section-6 and provide at least the parameters grant_type and refresh_token. An example, based on the one from the RFC:

POST /adfs/oauth2/token HTTP/1.1
Host: myadfsdomain
Content-Type: application/x-www-form-urlencoded

grant_type=refresh_token&refresh_token=<blahblah...>
like image 183
Hans Z. Avatar answered Apr 06 '23 01:04

Hans Z.