token method
Token endpoint
Exchanges an authorization code for tokens, or refreshes tokens. Supports grant types: - authorization_code: Exchange code for tokens - refresh_token: Refresh access token - client_credentials: Get tokens for a confidential client
Parameters:
-
String grantType (required):
-
String code: Authorization code (for authorization_code grant)
-
String redirectUri: Redirect URI (must match the one used in authorization)
-
String clientId:
-
String clientSecret: Client secret (for confidential clients)
-
String codeVerifier: PKCE code verifier
-
String refreshToken: Refresh token (for refresh_token grant)
-
String scope: Requested scopes
Implementation
Future<OAuthTokenResponse?> token(String grantType, { String? code, String? redirectUri, String? clientId, String? clientSecret, String? codeVerifier, String? refreshToken, String? scope, }) async {
final response = await tokenWithHttpInfo(grantType, code: code, redirectUri: redirectUri, clientId: clientId, clientSecret: clientSecret, codeVerifier: codeVerifier, refreshToken: refreshToken, scope: scope, );
if (response.statusCode >= HttpStatus.badRequest) {
throw ApiException(response.statusCode, await _decodeBodyBytes(response));
}
// When a remote server returns no body with a status of 204, we shall not decode it.
// At the time of writing this, `dart:convert` will throw an "Unexpected end of input"
// FormatException when trying to decode an empty string.
if (response.body.isNotEmpty && response.statusCode != HttpStatus.noContent) {
return await apiClient.deserializeAsync(await _decodeBodyBytes(response), 'OAuthTokenResponse',) as OAuthTokenResponse;
}
return null;
}