Yahoo 및 C ++를 사용하여 인증
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
Firebase SDK를 통해 전체 로그인 과정을 수행하는 앱에 웹 기반의 일반 OAuth 로그인을 통합하여 사용자가 Yahoo와 같은 OAuth 제공업체를 통해 Firebase에 인증하도록 할 수 있습니다. 이 과정은 스마트폰 기반 Firebase SDK를 사용해야 하므로 Android 및 Apple 플랫폼에서만 지원됩니다.
시작하기 전에
- C++ 프로젝트에 Firebase를 추가합니다.
- Firebase Console에서 인증 섹션을 엽니다.
- 로그인 방법 탭에서 Yahoo 제공업체를 사용 설정합니다.
- 해당 제공업체의 개발자 콘솔에서 제공되는 클라이언트 ID 및 클라이언트 보안 비밀번호를 제공업체 구성에 추가합니다.
-
Yahoo OAuth 클라이언트를 등록하려면 Yahoo에 웹 애플리케이션을 등록하는 방법에 대한 Yahoo 개발자 문서를 따릅니다.
OpenID Connect API 권한 2개(profile
및 email
)를 선택해야 합니다.
- 이러한 제공업체에 앱을 등록할 때 프로젝트의
*.firebaseapp.com
도메인을 앱의 리디렉션 도메인으로 등록해야 합니다.
- 저장을 클릭합니다.
firebase::auth::Auth
클래스 액세스
Auth
클래스는 모든 API 호출에 대한 게이트웨이입니다.
- Auth 및 App 헤더 파일을 추가합니다.
#include "firebase/app.h"
#include "firebase/auth.h"
- 초기화 코드에서
firebase::App
클래스를 만듭니다.#if defined(__ANDROID__)
firebase::App* app =
firebase::App::Create(firebase::AppOptions(), my_jni_env, my_activity);
#else
firebase::App* app = firebase::App::Create(firebase::AppOptions());
#endif // defined(__ANDROID__)
firebase::App
의 firebase::auth::Auth
클래스를 획득합니다.
App
과 Auth
는 일대일 매핑 관계입니다.
firebase::auth::Auth* auth = firebase::auth::Auth::GetAuth(app);
Firebase SDK로 로그인 과정 처리하기
Firebase SDK로 로그인 과정을 처리하려면 다음 단계를 따르세요.
Yahoo에 적합한 제공업체 ID로 구성된 FederatedOAuthProviderData
의 인스턴스를 생성합니다.
firebase::auth::FederatedOAuthProviderData
provider_data(firebase::auth::YahooAuthProvider::kProviderId);
선택사항: OAuth 요청과 함께 전송하고자 하는 커스텀 OAuth 매개변수를 추가로 지정합니다.
// Prompt user to re-authenticate to Yahoo.
provider_data.custom_parameters["prompt"] = "login";
// Localize to French.
provider_data.custom_parameters["language"] = "fr";
Yahoo가 지원하는 매개변수 정보는 Yahoo OAuth 문서를 참조하세요.
Firebase에서 요구하는 매개변수는 custom_parameters()
와 함께 전달할 수 없습니다. 이러한 매개변수에는 client_id, redirect_uri, response_type, scope, state가 있습니다.
선택사항: 인증 제공업체에서 요청하고자 하는 profile
및 email
범위를 넘는 OAuth 2.0 범위를 추가로 지정합니다. 애플리케이션에서 Yahoo API의 비공개 사용자 데이터에 대한 액세스가 필요한 경우 Yahoo 개발자 콘솔의 API 권한에서 Yahoo API에 대한 권한을 요청해야 합니다. 요청받은 OAuth 범위는 앱의 API 권한에서 사전 구성된 범위와 정확하게 일치해야 합니다. 예를 들어 사용자 연락처에 읽기/쓰기 액세스 권한이 요청되고 앱의 API 권한에서 사전 구성되었다면 읽기 전용 OAuth 범위 sdct-r
대신 sdct-w
를 전달해야 합니다. 그렇지 않으면 과정이 실패하고 최종 사용자에게 오류가 표시됩니다.
// 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");
자세한 내용은 Yahoo 범위 문서를 참조하세요.
제공업체 데이터가 구성되었으면 이를 사용하여 FederatedOAuthProvider를 만듭니다.
// Construct a FederatedOAuthProvider for use in Auth methods.
firebase::auth::FederatedOAuthProvider provider(provider_data);
인증 제공업체 객체를 사용해 Firebase에 인증합니다. 이는 다른 FirebaseAuth 작업과 달리 사용자가 인증 정보를 입력할 수 있는 웹 보기를 표시하여 UI를 제어합니다.
로그인 과정을 시작하려면 다음과 같이 SignInWithProvider
를 호출합니다.
firebase::Future<firebase::auth::AuthResult> result =
auth->SignInWithProvider(provider_data);
그러면 애플리케이션이 대기하거나
Future에 콜백을 등록할 수 있습니다.
위의 예시는 로그인 과정에 중점을 두고 있지만 LinkWithProvider
를 사용하여 Yahoo 제공업체를 기존 사용자에 연결할 수도 있습니다. 예를 들어 여러 제공업체를 동일한 사용자에 연결하여 그 중 하나로 로그인하도록 허용할 수 있습니다.
firebase::Future<firebase::auth::AuthResult> result = user.LinkWithProvider(provider_data);
최근 로그인한 적이 있어야 진행할 수 있는 중요한 작업에 대해 새로운 사용자 인증 정보를 검색하는 데 사용할 수 있는 ReauthenticateWithProvider
와 동일한 패턴을 사용할 수 있습니다.
firebase::Future<firebase::auth::AuthResult> result =
user.ReauthenticateWithProvider(provider_data);
그러면 애플리케이션이 대기하거나
Future에 콜백을 등록할 수 있습니다.
고급: 수동으로 로그인 과정 처리하기
OAuth 액세스 토큰 기반의 사용자 인증 정보를 사용하여 직접 로그인할 수 있는 다른 Firebase 지원 OAuth 제공업체(예: Google, Facebook, Twitter)와 달리, Firebase 인증 서버에서 Yahoo OAuth 액세스 토큰의 사용자를 인증할 수 없으므로 Firebase 인증은 Yahoo와 같은 제공업체에 대해 동일한 인증 기능을 지원하지 못합니다.
이는 중요한 보안 요구사항으로, 한 프로젝트(공격자)에서 확보한 Yahoo OAuth 액세스 토큰을 사용하여 다른 프로젝트(피해자)에 로그인할 수 있는 재전송 공격에 애플리케이션과 웹사이트가 노출될 수 있습니다.
대신 Firebase 인증은 Firebase Console에 구성된 OAuth 클라이언트 ID와 보안 비밀을 사용하여 전체 OAuth 과정과 승인 코드 교환을 처리할 수 있는 기능을 제공합니다. 승인 코드는 특정 클라이언트 ID/보안 비밀과 함께 사용되어야 하므로, 한 프로젝트에서 확보한 승인 코드는 다른 프로젝트에 사용할 수 없습니다.
지원되지 않는 환경에서 이러한 제공업체를 사용해야 하는 경우 서드 파티 OAuth 라이브러리 및 Firebase 커스텀 인증을 사용해야 합니다. 서드 파티 라이브러리는 제공업체 인증에 필요하고 Firebase 커스텀 인증은 제공업체의 사용자 인증 정보를 커스텀 토큰으로 교환할 때 필요합니다.
다음 단계
사용자가 처음으로 로그인하면 신규 사용자 계정이 생성되고 사용자가 로그인할 때 사용한 사용자 인증 정보(사용자 이름과 비밀번호, 전화번호 또는 인증 제공업체 정보)에 연결됩니다. 이 신규 계정은 Firebase 프로젝트에 저장되며 사용자의 로그인 방법과 무관하게 프로젝트 내의 모든 앱에서 사용자를 식별하는 데 사용할 수 있습니다.
인증 제공업체의 사용자 인증 정보를 기존 사용자 계정에 연결하면 사용자가 여러 인증 제공업체를 통해 앱에 로그인할 수 있습니다.
사용자를 로그아웃시키려면 SignOut()
을 호출합니다.
auth->SignOut();
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2025-08-16(UTC)
[null,null,["최종 업데이트: 2025-08-16(UTC)"],[],[],null,["You can let your users authenticate with Firebase using OAuth providers like\nYahoo by integrating web-based generic OAuth Login into your app using the\nFirebase SDK to carry out the end to end sign-in flow. Since this flow requires\nthe use of the phone-based Firebase SDKs, it is only supported on Android and\nApple platforms.\n\nBefore you begin\n\n1. [Add Firebase to your C++ project](/docs/cpp/setup#note_select_platform).\n2. In the [Firebase console](//console.firebase.google.com/), open the **Auth** section.\n3. On the **Sign in method** tab, enable the **Yahoo** provider.\n4. Add the **Client ID** and **Client Secret** from that provider's developer console to the provider configuration:\n 1. To register a Yahoo OAuth client, follow the Yahoo developer\n documentation on [registering a web application with Yahoo](https://developer.yahoo.com/oauth2/guide/openid_connect/getting_started.html).\n\n Be sure to select the two OpenID Connect API permissions:\n `profile` and `email`.\n 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.\n5. Click **Save**.\n\nAccess the `firebase::auth::Auth` class The `Auth` class is the gateway for all API calls.\n\n1. Add the Auth and App header files: \n\n ```c++\n #include \"firebase/app.h\"\n #include \"firebase/auth.h\"\n ```\n2. In your initialization code, create a [`firebase::App`](/docs/reference/cpp/class/firebase/app) class. \n\n ```c++\n #if defined(__ANDROID__)\n firebase::App* app =\n firebase::App::Create(firebase::AppOptions(), my_jni_env, my_activity);\n #else\n firebase::App* app = firebase::App::Create(firebase::AppOptions());\n #endif // defined(__ANDROID__)\n ```\n3. Acquire the `firebase::auth::Auth` class for your `firebase::App`. There is a one-to-one mapping between `App` and `Auth`. \n\n ```c++\n firebase::auth::Auth* auth = firebase::auth::Auth::GetAuth(app);\n ```\n\nHandle the sign-in flow with the Firebase SDK\n\nTo handle the sign-in flow with the Firebase SDK, follow these steps:\n\n1. Construct an instance of a `FederatedOAuthProviderData` configured with\n the provider ID appropriate for Yahoo.\n\n firebase::auth::FederatedOAuthProviderData\n provider_data(firebase::auth::YahooAuthProvider::kProviderId);\n\n2. **Optional**: Specify additional custom OAuth parameters that you want to\n send with the OAuth request.\n\n // Prompt user to re-authenticate to Yahoo.\n provider_data.custom_parameters[\"prompt\"] = \"login\";\n\n // Localize to French.\n provider_data.custom_parameters[\"language\"] = \"fr\";\n\n For the parameters Yahoo supports, see the\n [Yahoo OAuth documentation](https://developer.yahoo.com/oauth2/guide/openid_connect/getting_started.html).\n Note that you can't pass Firebase-required parameters with\n `custom_parameters()`. These parameters are **client_id** ,\n **redirect_uri** , **response_type** , **scope** and **state**.\n3. **Optional** : Specify additional OAuth 2.0 scopes beyond `profile` and\n `email` that you want to request from the authentication provider. If your\n application requires access to private user data from Yahoo APIs, you'll\n need to request permissions to Yahoo APIs under **API Permissions** in the\n Yahoo developer console. Requested OAuth scopes must be exact matches to the\n preconfigured ones in the app's API permissions. For example if, read/write\n access is requested to user contacts and preconfigured in the app's API\n permissions, `sdct-w` has to be passed instead of the readonly OAuth scope\n `sdct-r`. Otherwise,the flow will fail and an error would be shown to the\n end user.\n\n // Request access to Yahoo Mail API.\n provider_data.scopes.push_back(\"mail-r\");\n // This must be preconfigured in the app's API permissions.\n provider_data.scopes.push_back(\"sdct-w\");\n\n To learn more, refer to the\n [Yahoo scopes documentation](https://developer.yahoo.com/oauth2/guide/yahoo_scopes/).\n4. Once your provider data has been configured, use it to create a\n FederatedOAuthProvider.\n\n // Construct a FederatedOAuthProvider for use in Auth methods.\n firebase::auth::FederatedOAuthProvider provider(provider_data);\n\n5. Authenticate with Firebase using the Auth provider object. Note that unlike\n other FirebaseAuth operations, this will take control of your UI by popping\n up a web view in which the user can enter their credentials.\n\n To start the sign in flow, call `SignInWithProvider`: \n\n firebase::Future\u003cfirebase::auth::AuthResult\u003e result =\n auth-\u003eSignInWithProvider(provider_data);\n\n Your application may then wait or [register a callback on the Future](#register_callback_on_future).\n6. While the above examples focus on sign-in flows, you also have the\n ability to link a Yahoo provider to an existing user using\n `LinkWithProvider`. For example, you can link multiple\n providers to the same user allowing them to sign in with either.\n\n firebase::Future\u003cfirebase::auth::AuthResult\u003e result = user.LinkWithProvider(provider_data);\n\n7. The same pattern can be used with `ReauthenticateWithProvider` which can be\n used to retrieve fresh credentials for sensitive operations that require\n recent login.\n\n firebase::Future\u003cfirebase::auth::AuthResult\u003e result =\n user.ReauthenticateWithProvider(provider_data);\n\n Your application may then wait or [register a callback on\n the Future](#register_callback_on_future).\n\nAdvanced: Handle the sign-in flow manually\n\nUnlike other OAuth providers supported by Firebase such as Google, Facebook,\nand Twitter, where sign-in can directly be achieved with OAuth access token\nbased credentials, Firebase Auth does not support the same capability for\nproviders such as Yahoo due to the inability of the Firebase\nAuth server to verify the audience of Yahoo OAuth access tokens.\nThis is a critical security requirement and could expose applications and\nwebsites to replay attacks where a Yahoo OAuth access token obtained for\none project (attacker) can be used to sign in to another project (victim).\nInstead, Firebase Auth offers the ability to handle the entire OAuth flow and\nthe authorization code exchange using the OAuth client ID and secret\nconfigured in the Firebase Console. As the authorization code can only be used\nin conjunction with a specific client ID/secret, an authorization code\nobtained for one project cannot be used with another.\n\nIf these providers are required to be used in unsupported environments, a\nthird party OAuth library and\n[Firebase custom authentication](../admin/create-custom-tokens)\nwould need to be used. The former is needed to authenticate with the provider\nand the latter to exchange the provider's credential for a custom token.\n\nNext steps\n\nAfter a user signs in for the first time, a new user account is created and\nlinked to the credentials---that is, the user name and password, phone\nnumber, or auth provider information---the user signed in with. This new\naccount is stored as part of your Firebase project, and can be used to identify\na user across every app in your project, regardless of how the user signs in.\n\n- In your apps, you can get the user's basic profile information from the\n [`firebase::auth::User`](/docs/reference/cpp/class/firebase/auth/user) object:\n\n ```c++\n firebase::auth::User user = auth-\u003ecurrent_user();\n if (user.is_valid()) {\n std::string name = user.display_name();\n std::string email = user.email();\n std::string photo_url = user.photo_url();\n // The user's ID, unique to the Firebase project.\n // Do NOT use this value to authenticate with your backend server,\n // if you have one. Use firebase::auth::User::Token() instead.\n std::string uid = user.uid();\n }\n ```\n- In your Firebase Realtime Database and Cloud Storage\n [Security Rules](/docs/database/security/user-security), you can\n get the signed-in user's unique user ID from the `auth` variable,\n and use it to control what data a user can access.\n\nYou can allow users to sign in to your app using multiple authentication\nproviders by [linking auth provider credentials to an\nexisting user account.](/docs/auth/cpp/account-linking)\n\nTo sign out a user, call [`SignOut()`](/docs/reference/cpp/class/firebase/auth/auth#signout): \n\n```c++\nauth-\u003eSignOut();\n```"]]