requestAuthorization method

Future<AuthorizationResponse> requestAuthorization({
  1. required String clientId,
  2. List<String>? scopes,
  3. String? codeChallenge,
  4. bool enableState = true,
  5. String? state,
  6. Map<String, dynamic>? customParams,
  7. BaseWebAuth? webAuthClient,
  8. Map<String, dynamic>? webAuthOpts,
})

Requests an Authorization Code to be used in the Authorization Code grant.

Implementation

Future<AuthorizationResponse> requestAuthorization(
    {required String clientId,
    List<String>? scopes,
    String? codeChallenge,
    bool enableState = true,
    String? state,
    Map<String, dynamic>? customParams,
    BaseWebAuth? webAuthClient,
    Map<String, dynamic>? webAuthOpts}) async {
  webAuthClient ??= this.webAuthClient;

  if (enableState) {
    state ??= randomAlphaNumeric(25);
  }

  final authorizeUrl = getAuthorizeUrl(
      clientId: clientId,
      redirectUri: redirectUri,
      scopes: scopes,
      enableState: enableState,
      state: state,
      codeChallenge: codeChallenge,
      customParams: customParams);

  // Present the dialog to the user
  final result = await webAuthClient.authenticate(
      url: authorizeUrl,
      callbackUrlScheme: customUriScheme,
      redirectUrl: redirectUri,
      opts: webAuthOpts);

  return AuthorizationResponse.fromRedirectUri(result, state);
}