getAuthorizeUrl method

String getAuthorizeUrl({
  1. required String clientId,
  2. String responseType = 'code',
  3. String? redirectUri,
  4. List<String>? scopes,
  5. bool enableState = true,
  6. String? state,
  7. String? codeChallenge,
  8. Map<String, dynamic>? customParams,
})

Generates the url to be used for fetching the authorization code.

Implementation

String getAuthorizeUrl(
    {required String clientId,
    String responseType = 'code',
    String? redirectUri,
    List<String>? scopes,
    bool enableState = true,
    String? state,
    String? codeChallenge,
    Map<String, dynamic>? customParams}) {
  final params = <String, dynamic>{
    'response_type': responseType,
    'client_id': clientId
  };

  if (redirectUri != null && redirectUri.isNotEmpty) {
    params['redirect_uri'] = redirectUri;
  }

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

  if (enableState && state != null && state.isNotEmpty) {
    params['state'] = state;
  }

  if (codeChallenge != null && codeChallenge.isNotEmpty) {
    params['code_challenge'] = codeChallenge;
    params['code_challenge_method'] = 'S256';
  }

  if (customParams != null) {
    params.addAll(customParams);
  }

  return OAuth2Utils.addParamsToUrl(authorizeUrl, params);
}