buildOAuthAuthorizationParameters<TProfile extends Object> function

Map<String, String> buildOAuthAuthorizationParameters<TProfile extends Object>(
  1. OAuthProvider<TProfile> provider, {
  2. required String state,
  3. String? codeChallenge,
  4. String? nonce,
  5. String? callbackUrl,
})

Builds OAuth authorization query parameters for provider.

Implementation

Map<String, String> buildOAuthAuthorizationParameters<TProfile extends Object>(
  OAuthProvider<TProfile> provider, {
  required String state,
  String? codeChallenge,
  String? nonce,
  String? callbackUrl,
}) {
  final codeChallengeMethod = codeChallenge == null ? null : 'S256';
  final params = <String, String>{
    for (final entry in provider.authorizationParams.entries)
      if (!_oauthAuthorizationReservedParameters.contains(entry.key))
        entry.key: entry.value,
    'response_type': 'code',
    'client_id': provider.clientId,
    'redirect_uri': provider.redirectUri,
    'state': state,
    'nonce': ?nonce,
    if (provider.scopes.isNotEmpty) 'scope': provider.scopes.join(' '),
    'code_challenge': ?codeChallenge,
    'code_challenge_method': ?codeChallengeMethod,
  };
  if (callbackUrl != null && callbackUrl.isNotEmpty) {
    params['callbackUrl'] = callbackUrl;
  }
  return params;
}