Authenticate Using Yahoo and C++

You can let your users authenticate with Firebase using OAuth providers likeYahoo by integrating web-based generic OAuth Login into your app using theFirebase SDK to carry out the end to end sign-in flow. Since this flow requiresthe use of the phone-based Firebase SDKs, it is only supported on Android andApple platforms.

Before you begin

  1. Add Firebase to your C++ project.
  2. In theFirebase console, open theAuth section.
  3. On theSign in method tab, enable theYahoo provider.
  4. Add theClient ID andClient Secret from that provider's developer console to the provider configuration:
    1. To register a Yahoo OAuth client, follow the Yahoo developer documentation on registering a web application with Yahoo.

      Be sure to select the two OpenID Connect API permissions:profile andemail.

    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. ClickSave.

Access thefirebase::auth::Auth class

TheAuth class is the gateway for all API calls.
  1. Add the Auth and App header files:
    #include"firebase/app.h"#include"firebase/auth.h"
  2. In your initialization code, create afirebase::App class.
    #if defined(__ANDROID__)firebase::App*app=firebase::App::Create(firebase::AppOptions(),my_jni_env,my_activity);#elsefirebase::App*app=firebase::App::Create(firebase::AppOptions());#endif// defined(__ANDROID__)
  3. Acquire thefirebase::auth::Auth class for yourfirebase::App.There is a one-to-one mapping betweenApp andAuth.
    firebase::auth::Auth*auth=firebase::auth::Auth::GetAuth(app);

Handle the sign-in flow with the Firebase SDK

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

  1. Construct an instance of aFederatedOAuthProviderData configured withthe provider ID appropriate for Yahoo.

    firebase::auth::FederatedOAuthProviderDataprovider_data(firebase::auth::YahooAuthProvider::kProviderId);
  2. Optional: Specify additional custom OAuth parameters that you want tosend with the OAuth request.

    // Prompt user to re-authenticate to Yahoo.provider_data.custom_parameters["prompt"]="login";// Localize to French.provider_data.custom_parameters["language"]="fr";

    For the parameters Yahoo supports, see theYahoo OAuth documentation.Note that you can't pass Firebase-required parameters withcustom_parameters(). These parameters areclient_id,redirect_uri,response_type,scope andstate.

  3. Optional: Specify additional OAuth 2.0 scopes beyondprofile andemail that you want to request from the authentication provider. If yourapplication requires access to private user data from Yahoo APIs, you'llneed to request permissions to Yahoo APIs underAPI Permissions in theYahoo developer console. Requested OAuth scopes must be exact matches to thepreconfigured ones in the app's API permissions. For example if, read/writeaccess is requested to user contacts and preconfigured in the app's APIpermissions,sdct-w has to be passed instead of the readonly OAuth scopesdct-r. Otherwise,the flow will fail and an error would be shown to theend user.

    // Request access to Yahoo Mail API.provider_data.scopes.push_back("mail-r");// This must be preconfigured in the app's API permissions.provider_data.scopes.push_back("sdct-w");

    To learn more, refer to theYahoo scopes documentation.

  4. Once your provider data has been configured, use it to create aFederatedOAuthProvider.

    // Construct a FederatedOAuthProvider for use in Auth methods.firebase::auth::FederatedOAuthProviderprovider(provider_data);
  5. Authenticate with Firebase using the Auth provider object. Note that unlikeother FirebaseAuth operations, this will take control of your UI by poppingup a web view in which the user can enter their credentials.

    To start the sign in flow, callSignInWithProvider:

    firebase::Future<firebase::auth::AuthResult>result=auth->SignInWithProvider(provider_data);

    Your application may then wait orregister a callback on the Future.

  6. While the above examples focus on sign-in flows, you also have theability to link a Yahoo provider to an existing user usingLinkWithProvider. For example, you can link multipleproviders to the same user allowing them to sign in with either.

    firebase::Future<firebase::auth::AuthResult>result=user.LinkWithProvider(provider_data);
  7. The same pattern can be used withReauthenticateWithProvider which can beused to retrieve fresh credentials for sensitive operations that requirerecent login.

    firebase::Future<firebase::auth::AuthResult>result=user.ReauthenticateWithProvider(provider_data);

    Your application may then wait orregister a callback onthe Future.

Advanced: Handle the sign-in flow manually

Unlike other OAuth providers supported by Firebase such as Google, Facebook, and Twitter, where sign-in can directly be achieved with OAuth access token based credentials, Firebase Auth does not support the same capability for providers such as Yahoo due to the inability of the Firebase Auth server to verify the audience of Yahoo OAuth access tokens. This is a critical security requirement and could expose applications and websites to replay attacks where a Yahoo OAuth access token obtained for one project (attacker) can be used to sign in to another project (victim). Instead, Firebase Auth offers the ability to handle the entire OAuth flow and the authorization code exchange using the OAuth client ID and secret configured in the Firebase Console. As the authorization code can only be used in conjunction with a specific client ID/secret, an authorization code obtained for one project cannot be used with another.

If these providers are required to be used in unsupported environments, a third party OAuth library andFirebase custom authentication would need to be used. The former is needed to authenticate with the provider and the latter to exchange the provider's credential for a custom token.

Next steps

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

  • In your apps, you can get the user's basic profile information from thefirebase::auth::User object:

    firebase::auth::Useruser=auth->current_user();if(user.is_valid()){std::stringname=user.display_name();std::stringemail=user.email();std::stringphoto_url=user.photo_url();// The user's ID, unique to the Firebase project.// Do NOT use this value to authenticate with your backend server,// if you have one. Use firebase::auth::User::Token() instead.std::stringuid=user.uid();}
  • In yourFirebase Realtime Database andCloud StorageSecurity Rules, you can get the signed-in user's unique user ID from theauth variable, and use it to control what data a user can access.

You can allow users to sign in to your app using multiple authenticationproviders bylinking auth provider credentials to anexisting user account.

To sign out a user, callSignOut():

auth->SignOut();

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-12-17 UTC.