createAuthHandlerUrl static method

Uri createAuthHandlerUrl({
  1. required FirebaseApp app,
  2. required String authType,
  3. String? providerId,
  4. List<String>? scopes,
  5. Map? parameters,
})

Implementation

static Uri createAuthHandlerUrl({
  required FirebaseApp app,
  required String authType,
  String? providerId,
  List<String>? scopes,
  Map<dynamic, dynamic>? parameters,
}) {
  var eventId = Uuid().v4();

  var sessionId = _randomString();

  var platform = Platform.current;

  var url = Uri(
      scheme: 'https',
      host: app.options.authDomain,
      path: '__/auth/handler',
      queryParameters: {
        // TODO: version 'v': 'X$clientVersion',
        'authType': authType,
        'apiKey': app.options.apiKey,
        if (providerId != null) 'providerId': providerId,
        if (scopes != null && scopes.isNotEmpty) 'scopes': scopes.join(','),
        if (parameters != null) 'customParameters': json.encode(parameters),
        // TODO: if (tenantId != null) 'tid': tenantId

        'eventId': eventId,

        if (platform is AndroidPlatform) ...{
          'eid': 'p',
          'sessionId': sessionId,
          'apn': platform.packageId,
          'sha1Cert': platform.sha1Cert.replaceAll(':', '').toLowerCase(),
          'publicKey':
              '...', // seems encryption is not used, but public key needs to be present to assemble the correct redirect url
        },
        if (platform is IOsPlatform) ...{
          'sessionId': sessionId,
          'ibi': platform.appId,
          if (app.options.iosClientId != null)
            'clientId': app.options.iosClientId
          else
            'appId': app.options.appId,
        },
        if (platform is MacOsPlatform) ...{
          'sessionId': sessionId,
          'ibi': platform.appId,
          if (app.options.iosClientId != null)
            'clientId': app.options.iosClientId
          else
            'appId': app.options.appId,
        },
        if (platform is WebPlatform) ...{
          'redirectUrl': platform.currentUrl,
          'appName': app.name,
        }
      });
  return url;
}