firebaseui.auth.widget.handler.common.getAuthProvider_ = function()

in javascript/widgets/handler/common.js [450:498]


firebaseui.auth.widget.handler.common.getAuthProvider_ = function(
    app, providerId, opt_email) {
  // Construct provider and pass additional scopes.
  var provider = firebaseui.auth.idp.getAuthProvider(providerId);
  // Provider must be provided for any action to be taken.
  if (!provider) {
    // This shouldn't happen.
    throw new Error('Invalid Firebase Auth provider!');
  }
  // Get additional scopes for requested provider.
  var additionalScopes =
      app.getConfig().getProviderAdditionalScopes(providerId);
  // Some providers like Twitter do not accept additional scopes.
  if (provider['addScope']) {
    // Add every requested additional scope to the provider.
    for (var i = 0; i < additionalScopes.length; i++) {
      provider['addScope'](additionalScopes[i]);
    }
  }
  // Get custom parameters for the selected provider.
  var customParameters =
      app.getConfig().getProviderCustomParameters(providerId) || {};
  // Some providers accept an email address as a login hint. If the email is
  // set and if the provider supports it, add it to the custom paramaters.
  if (opt_email) {
    var loginHintKey;
    // Since the name of the parameter is known for Google and GitHub, set this
    // automatically. Google and GitHub are the only default providers which
    // support a login hint.
    if (providerId == firebase.auth.GoogleAuthProvider.PROVIDER_ID) {
      loginHintKey = 'login_hint';
    } else if (providerId == firebase.auth.GithubAuthProvider.PROVIDER_ID) {
      loginHintKey = 'login';
    } else {
      // For other providers, check if the name is set in the configuration.
      var providerConfig = app.getConfig().getConfigForProvider(providerId);
      loginHintKey = providerConfig && providerConfig.loginHintKey;
    }
    // If the hint is set, add the email to the custom parameters.
    if (loginHintKey) {
      customParameters[loginHintKey] = opt_email;
    }
  }
  // Set the custom parameters if applicable for the current provider.
  if (provider.setCustomParameters) {
    provider.setCustomParameters(customParameters);
  }
  return provider;
};