tokenWithHttpInfo 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
Note: This method returns the HTTP Response.
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<Response> tokenWithHttpInfo(String grantType, { String? code, String? redirectUri, String? clientId, String? clientSecret, String? codeVerifier, String? refreshToken, String? scope, }) async {
// ignore: prefer_const_declarations
final path = r'/oauth/token';
// ignore: prefer_final_locals
Object? postBody;
final queryParams = <QueryParam>[];
final headerParams = <String, String>{};
final formParams = <String, String>{};
const contentTypes = <String>['application/x-www-form-urlencoded'];
if (grantType != null) {
formParams[r'grant_type'] = parameterToString(grantType);
}
if (code != null) {
formParams[r'code'] = parameterToString(code);
}
if (redirectUri != null) {
formParams[r'redirect_uri'] = parameterToString(redirectUri);
}
if (clientId != null) {
formParams[r'client_id'] = parameterToString(clientId);
}
if (clientSecret != null) {
formParams[r'client_secret'] = parameterToString(clientSecret);
}
if (codeVerifier != null) {
formParams[r'code_verifier'] = parameterToString(codeVerifier);
}
if (refreshToken != null) {
formParams[r'refresh_token'] = parameterToString(refreshToken);
}
if (scope != null) {
formParams[r'scope'] = parameterToString(scope);
}
return apiClient.invokeAPI(
path,
'POST',
queryParams,
postBody,
headerParams,
formParams,
contentTypes.isEmpty ? null : contentTypes.first,
);
}