exchangeRefreshTokenForAccessToken method

Future<ClientResponse<AccessToken, OAuthError>> exchangeRefreshTokenForAccessToken(
  1. String refresh_token,
  2. String client_id,
  3. String client_secret,
  4. String scope,
  5. String user_code,
)

Exchange a Refresh Token for an Access Token. If you will be using the Refresh Token Grant, you will make a request to the Token endpoint to exchange the user’s refresh token for an access token.

@param {String} refresh_token The refresh token that you would like to use to exchange for an access token. @param {String} client_id (Optional) The unique client identifier. The client Id is the Id of the FusionAuth Application in which you are attempting to authenticate. This parameter is optional when the Authorization header is provided. This parameter is optional when Basic Authorization is used to authenticate this request. @param {String} client_secret (Optional) The client secret. This value may optionally be provided in the request body instead of the Authorization header. @param {String} scope (Optional) This parameter is optional and if omitted, the same scope requested during the authorization request will be used. If provided the scopes must match those requested during the initial authorization request. @param {String} user_code (Optional) The end-user verification code. This code is required if using this endpoint to approve the Device Authorization. @returns {Promise<ClientResponse

Implementation

Future<ClientResponse<AccessToken, OAuthError>>
    exchangeRefreshTokenForAccessToken(String refresh_token, String client_id,
        String client_secret, String scope, String user_code) {
  var body = <String, dynamic>{};
  body['refresh_token'] = refresh_token;
  body['client_id'] = client_id;
  body['client_secret'] = client_secret;
  body['grant_type'] = 'refresh_token';
  body['scope'] = scope;
  body['user_code'] = user_code;
  return _startAnonymous<AccessToken, OAuthError>()
      .withUri('/oauth2/token')
      .withFormData(body)
      .withMethod('POST')
      .withResponseHandler(
          defaultResponseHandlerBuilder((d) => AccessToken.fromJson(d)))
      .go();
}