Go to console

Authenticate Using Yahoo with JavaScript

You can let your users authenticate with Firebase using OAuth providers like Yahoo by integrating generic OAuth Login into your app using the Firebase SDK to carry out the end to end sign-in flow.

Before you begin

To sign in users using Yahoo accounts, you must first enable Yahoo as a sign-in provider for your Firebase project:

  1. Add Firebase to your JavaScript project.
  2. In the Firebase console, open the Auth section.
  3. On the Sign in method tab, enable the Yahoo provider.
  4. Add the Client ID and Client Secret from that provider's developer console to the provider configuration:
    1. To register a Yahoo OAuth client, follow the Yahoo instructions on registering a web application with Yahoo.
    2. When registering apps with these providers, be sure to register the *.firebaseapp.com domain for your project as the redirect domain for your app.
  5. Click Save.

Handle the sign-in flow with the Firebase SDK

If you are building a web app, the easiest way to authenticate your users with Firebase using their Yahoo accounts is to handle the entire sign-in flow with the Firebase JavaScript SDK.

To handle the sign-in flow with the Firebase JavaScript SDK, follow these steps:

  1. Create an instance of an OAuthProvider using the provider ID yahoo.com.

    var provider = new firebase.auth.OAuthProvider('yahoo.com');
    
  2. Optional: Specify additional custom OAuth parameters that you want to send with the OAuth request.

    provider.setCustomParameters({
      // Prompt user to re-authenticate to Yahoo.
      prompt: 'login',
      // Localize to French.
      language: 'fr'
    });
    

    For the parameters Yahoo supports, see the Yahoo OAuth documentation. Note that you can't pass Firebase-required parameters with setCustomParameters(). These parameters are client_id, redirect_uri, response_type, scope and state.

  3. Optional: Specify additional OAuth 2.0 scopes beyond basic profile that you want to request from the authentication provider. If your application requires access to private user data from Yahoo APIs, you'll need to request permissions to access Yahoo APIs under API Permissions in the Yahoo developer console. Requested OAuth scopes must be exact matches to the preconfigured ones in the app's API permissions. For example if, read/write access is requested to user contacts and preconfigured in the app's API permissions, sdct-w has to be passed instead of the readonly OAuth scope sdct-r. Otherwise, the flow will fail and an error would be shown to the end user.

    // Request access to Yahoo Mail API.
    provider.addScope('mail-r');
    // Request read/write access to user contacts.
    // This must be preconfigured in the app's API permissions.
    provider.addScope('sdct-w');
    

    To learn more, refer to the Yahoo scopes documentation.

  4. Authenticate with Firebase using the OAuth provider object. You can prompt your users to sign in with their Yahoo Accounts either by opening a pop-up window or by redirecting to the sign-in page. The redirect method is preferred on mobile devices.

    • To sign in with a pop-up window, call signInWithPopup:

      firebase.auth().signInWithPopup(provider)
        .then(function(result) {
          // User is signed in.
          // IdP data available in result.additionalUserInfo.profile.
          // Yahoo OAuth access token can be retrieved by calling:
          // result.credential.accessToken
          // Yahoo OAuth ID token can be retrieved by calling:
          // result.credential.idToken
        })
        .catch(function(error) {
          // Handle error.
        });
      
    • To sign in by redirecting to the sign-in page, call signInWithRedirect:

      firebase.auth().signInWithRedirect(provider);
      

      After the user completes sign-in and returns to the page, you can obtain the sign-in result by calling getRedirectResult.

      firebase.auth().getRedirectResult()
        .then(function(result) {
          // User is signed in.
          // IdP data available in result.additionalUserInfo.profile.
          // Yahoo OAuth access token can be retrieved by calling:
          // result.credential.accessToken
          // Yahoo OAuth ID token can be retrieved by calling:
          // result.credential.idToken
        })
        .catch(function(error) {
          // Handle error.
        });
      

    On successful completion, the OAuth ID token and access token associated with the provider can be retrieved from the firebase.auth.UserCredential object returned.

    Using the OAuth access token, you can call the Yahoo API.

    For example, to get the basic profile information, the following REST API can be called:

    curl -i -H "Authorization: Bearer ACCESS_TOKEN" https://social.yahooapis.com/v1/user/YAHOO_USER_UID/profile?format=json
    

    Where YAHOO_USER_UID is the Yahoo user's ID which can be retrieved from the firebase.auth().currentUser.providerData[0].uid field or from result.additionalUserInfo.profile.

  5. While the above examples focus on sign-in flows, you also have the ability to link a Yahoo provider to an existing user using linkWithPopup/linkWithRedirect. For example, you can link multiple providers to the same user allowing them to sign in with either.

    var provider = new firebase.auth.OAuthProvider('yahoo.com');
    firebase.auth().currentUser.linkWithPopup(provider)
        .then(function(result) {
          // Yahoo credential is linked to the current user.
          // IdP data available in result.additionalUserInfo.profile.
          // Yahoo OAuth access token can be retrieved by calling:
          // result.credential.accessToken
          // Yahoo OAuth ID token can be retrieved by calling:
          // result.credential.idToken
        })
        .catch(function(error) {
          // Handle error.
        });
    
  6. The same pattern can be used with reauthenticateWithPopup/reauthenticateWithRedirect which can be used to retrieve fresh credentials for sensitive operations that require recent login.

    var provider = new firebase.auth.OAuthProvider('yahoo.com');
    firebase.auth().currentUser.reauthenticateWithPopup(provider)
        .then(function(result) {
          // User is re-authenticated with fresh tokens minted and
          // should be able to perform sensitive operations like account
          // deletion and email or password update.
          // IdP data available in result.additionalUserInfo.profile.
          // Yahoo OAuth access token can be retrieved by calling:
          // result.credential.accessToken
          // Yahoo OAuth ID token can be retrieved by calling:
          // result.credential.idToken
        })
        .catch(function(error) {
          // Handle error.
        });
    

Authenticate with Firebase in a Chrome extension

If you are building a Chrome extension app, you must whitelist your Chrome extension ID:

  1. Open your project in the Firebase console.
  2. In the Authentication section, open the Sign-in method page.
  3. Add a URI like the following to the list of Authorized Domains:
    chrome-extension://CHROME_EXTENSION_ID

Only popup operations (signInWithPopup and linkWithPopup) are available to Chrome extensions, as Chrome extensions cannot use HTTP redirects. You should call these methods from a background script rather than a browser action popup, as the authentication popup will cancel the browser action popup.

In your Chrome extension's manifest file make sure that you add the https://apis.google.com URL to the content_security_policy whitelist.

Next steps

After a user signs in for the first time, a new user account is created and linked to the credentials—that is, the user name and password, phone number, or auth provider information—the user signed in with. This new account is stored as part of your Firebase project, and can be used to identify a user across every app in your project, regardless of how the user signs in.

  • In your apps, the recommended way to know the auth status of your user is to set an observer on the Auth object. You can then get the user's basic profile information from the User object. See Manage Users.

  • In your Firebase Realtime Database and Cloud Storage Security Rules, you can get the signed-in user's unique user ID from the auth variable, and use it to control what data a user can access.

You can allow users to sign in to your app using multiple authentication providers by linking auth provider credentials to an existing user account.

To sign out a user, call signOut:

firebase.auth().signOut().then(function() {
  // Sign-out successful.
}).catch(function(error) {
  // An error happened.
});