getTokenWithClientCredentialsFlow method

Future<AccessTokenResponse> getTokenWithClientCredentialsFlow({
  1. required String clientId,
  2. required String clientSecret,
  3. List<String>? scopes,
  4. Map<String, String>? customHeaders,
  5. dynamic httpClient,
})

Requests an Access Token to the OAuth2 endpoint using the Client Credentials flow.

Implementation

Future<AccessTokenResponse> getTokenWithClientCredentialsFlow(
    {required String clientId,
    required String clientSecret,
    List<String>? scopes,
    Map<String, String>? customHeaders,
    httpClient}) async {
  var params = <String, String>{'grant_type': 'client_credentials'};

  if (scopes != null && scopes.isNotEmpty) {
    params['scope'] = serializeScopes(scopes);
  }

  var response = await _performAuthorizedRequest(
      url: tokenUrl,
      clientId: clientId,
      clientSecret: clientSecret,
      params: params,
      headers: customHeaders,
      httpClient: httpClient);

  return http2TokenResponse(response, requestedScopes: scopes);
}