exchangeUserCredentialsForAccessToken method
Exchange User Credentials for a Token. If you will be using the Resource Owner Password Credential Grant, you will make a request to the Token endpoint to exchange the user’s email and password for an access token.
@param {String} username The login identifier of the user. The login identifier can be either the email or the username. @param {String} password The user’s password. @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>>
exchangeUserCredentialsForAccessToken(
String username,
String password,
String client_id,
String client_secret,
String scope,
String user_code) {
var body = <String, dynamic>{};
body['username'] = username;
body['password'] = password;
body['client_id'] = client_id;
body['client_secret'] = client_secret;
body['grant_type'] = 'password';
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();
}