getTokenWithPasswordGrantFlow method

Future<AccessTokenResponse> getTokenWithPasswordGrantFlow({
  1. required String clientId,
  2. required String clientSecret,
  3. List<String>? scopes,
  4. required String username,
  5. required String password,
  6. dynamic httpClient,
})

Requests an Access Token to the OAuth2 endpoint using the Password Grant flow.

Implementation

Future<AccessTokenResponse> getTokenWithPasswordGrantFlow(
    {required String clientId,
    required String clientSecret,
    List<String>? scopes,
    required String username,
    required String password,
    httpClient}) async {
  var params = <String, String>{
    'grant_type': 'password',
    'username': username,
    'password': password
    };

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

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

  return http2TokenResponse(response, requestedScopes: scopes);
}