createToken method
Creates and returns an access token for the authorized client. The access token issued will be used to fetch short-term credentials for the assigned roles in the AWS account.
May throw InvalidRequestException. May throw InvalidClientException. May throw InvalidGrantException. May throw UnauthorizedClientException. May throw UnsupportedGrantTypeException. May throw InvalidScopeException. May throw AuthorizationPendingException. May throw SlowDownException. May throw AccessDeniedException. May throw ExpiredTokenException. May throw InternalServerException.
Parameter clientId
:
The unique identifier string for each client. This value should come from
the persisted result of the RegisterClient API.
Parameter clientSecret
:
A secret string generated for the client. This value should come from the
persisted result of the RegisterClient API.
Parameter deviceCode
:
Used only when calling this API for the device code grant type. This
short-term code is used to identify this authentication attempt. This
should come from an in-memory reference to the result of the
StartDeviceAuthorization API.
Parameter grantType
:
Supports grant types for authorization code, refresh token, and device
code request.
Parameter code
:
The authorization code received from the authorization service. This
parameter is required to perform an authorization grant request to get
access to a token.
Parameter redirectUri
:
The location of the application that will receive the authorization code.
Users authorize the service to send the request to this location.
Parameter refreshToken
:
The token used to obtain an access token in the event that the access
token is invalid or expired. This token is not issued by the service.
Parameter scope
:
The list of scopes that is defined by the client. Upon authorization, this
list is used to restrict permissions when granting an access token.
Implementation
Future<CreateTokenResponse> createToken({
required String clientId,
required String clientSecret,
required String deviceCode,
required String grantType,
String? code,
String? redirectUri,
String? refreshToken,
List<String>? scope,
}) async {
ArgumentError.checkNotNull(clientId, 'clientId');
ArgumentError.checkNotNull(clientSecret, 'clientSecret');
ArgumentError.checkNotNull(deviceCode, 'deviceCode');
ArgumentError.checkNotNull(grantType, 'grantType');
final $payload = <String, dynamic>{
'clientId': clientId,
'clientSecret': clientSecret,
'deviceCode': deviceCode,
'grantType': grantType,
if (code != null) 'code': code,
if (redirectUri != null) 'redirectUri': redirectUri,
if (refreshToken != null) 'refreshToken': refreshToken,
if (scope != null) 'scope': scope,
};
final response = await _protocol.send(
payload: $payload,
method: 'POST',
requestUri: '/token',
signed: false,
exceptionFnMap: _exceptionFns,
);
return CreateTokenResponse.fromJson(response);
}