Facebook লগইন এবং C++ ব্যবহার করে প্রমাণীকরণ করুন
সেভ করা পৃষ্ঠা গুছিয়ে রাখতে 'সংগ্রহ' ব্যবহার করুন
আপনার পছন্দ অনুযায়ী কন্টেন্ট সেভ করুন ও সঠিক বিভাগে রাখুন।
আপনি আপনার অ্যাপে Facebook লগইন সংহত করে আপনার ব্যবহারকারীদের তাদের Facebook অ্যাকাউন্ট ব্যবহার করে Firebase-এর মাধ্যমে প্রমাণীকরণ করতে দিতে পারেন।
আপনি শুরু করার আগে
- আপনার C++ প্রকল্পে Firebase যোগ করুন ।
- Facebook for Developers সাইটে, আপনার অ্যাপের জন্য অ্যাপ আইডি এবং একটি অ্যাপ সিক্রেট পান।
- ফেসবুক লগইন সক্ষম করুন:
- Firebase কনসোলে , Auth বিভাগটি খুলুন।
- সাইন ইন পদ্ধতি ট্যাবে, Facebook সাইন-ইন পদ্ধতি সক্ষম করুন এবং আপনি Facebook থেকে যে অ্যাপ আইডি এবং অ্যাপ সিক্রেট পেয়েছেন তা নির্দিষ্ট করুন।
- তারপর, নিশ্চিত করুন যে আপনার OAuth রিডাইরেক্ট URI (যেমন
my-app-12345.firebaseapp.com/__/auth/handler
) আপনার OAuth রিডাইরেক্ট ইউআরআইগুলির মধ্যে একটি হিসাবে আপনার Facebook অ্যাপের সেটিংস পৃষ্ঠায় Facebook-এর ডেভেলপারদের সাইটে প্রোডাক্টের জন্য তালিকাভুক্ত আছে। সেটিংস > Facebook লগইন কনফিগারেশন।
firebase::auth::Auth
ক্লাস অ্যাক্সেস করুন
Auth
ক্লাস হল সমস্ত API কলের গেটওয়ে।
- Auth এবং অ্যাপ হেডার ফাইল যোগ করুন:
#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 দিয়ে প্রমাণীকরণ করুন
- সাইন ইন করা Facebook ব্যবহারকারীর জন্য একটি অ্যাক্সেস টোকেন পেতে Android এবং iOS+ এর জন্য নির্দেশাবলী অনুসরণ করুন৷
- একজন ব্যবহারকারী সফলভাবে সাইন ইন করার পরে, একটি Firebase শংসাপত্রের জন্য অ্যাক্সেস টোকেন বিনিময় করুন এবং Firebase শংসাপত্র ব্যবহার করে Firebase এর সাথে প্রমাণীকরণ করুন:
firebase::auth::Credential credential =
firebase::auth::FacebookAuthProvider::GetCredential(access_token);
firebase::Future<firebase::auth::AuthResult> result =
auth->SignInAndRetrieveDataWithCredential(credential);
- যদি আপনার প্রোগ্রামে একটি আপডেট লুপ থাকে যা নিয়মিতভাবে চলে (বলুন প্রতি সেকেন্ডে 30 বা 60 বার), আপনি
Auth::SignInAndRetrieveDataWithCredentialLastResult
এর সাথে আপডেট প্রতি একবার ফলাফল পরীক্ষা করতে পারেন :firebase::Future<firebase::auth::AuthResult> result =
auth->SignInAndRetrieveDataWithCredentialLastResult();
if (result.status() == firebase::kFutureStatusComplete) {
if (result.error() == firebase::auth::kAuthErrorNone) {
firebase::auth::AuthResult auth_result = *result.result();
printf("Sign in succeeded for `%s`\n",
auth_result.user.display_name().c_str());
} else {
printf("Sign in failed with error '%s'\n", result.error_message());
}
}
অথবা, যদি আপনার প্রোগ্রাম ইভেন্ট চালিত হয়, আপনি ভবিষ্যতে একটি কলব্যাক নিবন্ধন করতে পছন্দ করতে পারেন।
একটি ভবিষ্যতে একটি কলব্যাক নিবন্ধন করুন
কিছু প্রোগ্রামে
Update
ফাংশন থাকে যা প্রতি সেকেন্ডে 30 বা 60 বার বলা হয়। উদাহরণস্বরূপ, অনেক গেম এই মডেল অনুসরণ করে। এই প্রোগ্রামগুলি অ্যাসিঙ্ক্রোনাস কলগুলি পোল করতে
LastResult
ফাংশনগুলিকে কল করতে পারে। যাইহোক, যদি আপনার প্রোগ্রাম ইভেন্ট চালিত হয়, আপনি কলব্যাক ফাংশন নিবন্ধন করতে পছন্দ করতে পারেন। একটি কলব্যাক ফাংশন ভবিষ্যত সমাপ্তির উপর বলা হয়।
void OnCreateCallback(const firebase::Future<firebase::auth::User*>& result,
void* user_data) {
// The callback is called when the Future enters the `complete` state.
assert(result.status() == firebase::kFutureStatusComplete);
// Use `user_data` to pass-in program context, if you like.
MyProgramContext* program_context = static_cast<MyProgramContext*>(user_data);
// Important to handle both success and failure situations.
if (result.error() == firebase::auth::kAuthErrorNone) {
firebase::auth::User* user = *result.result();
printf("Create user succeeded for email %s\n", user->email().c_str());
// Perform other actions on User, if you like.
firebase::auth::User::UserProfile profile;
profile.display_name = program_context->display_name;
user->UpdateUserProfile(profile);
} else {
printf("Created user failed with error '%s'\n", result.error_message());
}
}
void CreateUser(firebase::auth::Auth* auth) {
// Callbacks work the same for any firebase::Future.
firebase::Future<firebase::auth::AuthResult> result =
auth->CreateUserWithEmailAndPasswordLastResult();
// `&my_program_context` is passed verbatim to OnCreateCallback().
result.OnCompletion(OnCreateCallback, &my_program_context);
}
কলব্যাক ফাংশনটিও একটি ল্যাম্বডা হতে পারে, যদি আপনি পছন্দ করেন।
void CreateUserUsingLambda(firebase::auth::Auth* auth) {
// Callbacks work the same for any firebase::Future.
firebase::Future<firebase::auth::AuthResult> result =
auth->CreateUserWithEmailAndPasswordLastResult();
// The lambda has the same signature as the callback function.
result.OnCompletion(
[](const firebase::Future<firebase::auth::User*>& result,
void* user_data) {
// `user_data` is the same as &my_program_context, below.
// Note that we can't capture this value in the [] because std::function
// is not supported by our minimum compiler spec (which is pre C++11).
MyProgramContext* program_context =
static_cast<MyProgramContext*>(user_data);
// Process create user result...
(void)program_context;
},
&my_program_context);
}
পরবর্তী পদক্ষেপ
একজন ব্যবহারকারী প্রথমবার সাইন ইন করার পরে, একটি নতুন ব্যবহারকারীর অ্যাকাউন্ট তৈরি করা হয় এবং শংসাপত্রগুলির সাথে লিঙ্ক করা হয়—অর্থাৎ, ব্যবহারকারীর নাম এবং পাসওয়ার্ড, ফোন নম্বর, বা প্রমাণ প্রদানকারীর তথ্য — ব্যবহারকারী সাইন ইন করেছেন। এই নতুন অ্যাকাউন্টটি আপনার ফায়ারবেস প্রকল্পের অংশ হিসাবে সংরক্ষণ করা হয়েছে এবং ব্যবহারকারী কীভাবে সাইন ইন করুন না কেন, আপনার প্রকল্পের প্রতিটি অ্যাপ জুড়ে একজন ব্যবহারকারীকে শনাক্ত করতে ব্যবহার করা যেতে পারে।
আপনার অ্যাপে, আপনি firebase::auth::User
অবজেক্ট থেকে ব্যবহারকারীর মৌলিক প্রোফাইল তথ্য পেতে পারেন:
firebase::auth::User user = auth->current_user();
if (user.is_valid()) {
std::string name = user.display_name();
std::string email = user.email();
std::string photo_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::string uid = user.uid();
}
আপনার Firebase Realtime Database এবং Cloud Storage সুরক্ষা নিয়মে , আপনি auth
ভেরিয়েবল থেকে সাইন-ইন করা ব্যবহারকারীর অনন্য ব্যবহারকারী আইডি পেতে পারেন এবং ব্যবহারকারী কোন ডেটা অ্যাক্সেস করতে পারে তা নিয়ন্ত্রণ করতে এটি ব্যবহার করতে পারেন।
আপনি একটি বিদ্যমান ব্যবহারকারীর অ্যাকাউন্টে প্রমাণীকরণ প্রদানকারীর শংসাপত্র লিঙ্ক করে একাধিক প্রমাণীকরণ প্রদানকারী ব্যবহার করে ব্যবহারকারীদের আপনার অ্যাপে সাইন ইন করার অনুমতি দিতে পারেন।
একজন ব্যবহারকারীকে সাইন আউট করতে, SignOut()
কল করুন :
auth->SignOut();
অন্য কিছু উল্লেখ না করা থাকলে, এই পৃষ্ঠার কন্টেন্ট Creative Commons Attribution 4.0 License-এর অধীনে এবং কোডের নমুনাগুলি Apache 2.0 License-এর অধীনে লাইসেন্স প্রাপ্ত। আরও জানতে, Google Developers সাইট নীতি দেখুন। Java হল Oracle এবং/অথবা তার অ্যাফিলিয়েট সংস্থার রেজিস্টার্ড ট্রেডমার্ক।
2025-08-15 UTC-তে শেষবার আপডেট করা হয়েছে।
[null,null,["2025-08-15 UTC-তে শেষবার আপডেট করা হয়েছে।"],[],[],null,["You can let your users authenticate with Firebase using their Facebook accounts\nby integrating Facebook Login into your app.\n\nBefore you begin\n\n1. [Add Firebase to your C++ project](/docs/cpp/setup#note_select_platform).\n2. On the [Facebook for Developers](https://developers.facebook.com/) site, get the **App ID** and an **App Secret** for your app.\n3. Enable Facebook Login:\n 1. In the [Firebase console](//console.firebase.google.com/), open the **Auth** section.\n 2. On the **Sign in method** tab, enable the **Facebook** sign-in method and specify the **App ID** and **App Secret** you got from Facebook.\n 3. Then, make sure your **OAuth redirect URI** (e.g. `my-app-12345.firebaseapp.com/__/auth/handler`) is listed as one of your **OAuth redirect URIs** in your Facebook app's settings page on the [Facebook for Developers](https://developers.facebook.com/) site in the **Product Settings \\\u003e Facebook Login** config.\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\nAuthenticate with Firebase\n\n1. Follow instructions for [Android](/docs/auth/android/facebook-login#authenticate_with_firebase) and [iOS+](/docs/auth/ios/facebook-login#authenticate_with_firebase) to get an access token for the signed-in Facebook user.\n2. After a user successfully signs in, exchange the access token for a Firebase credential, and authenticate with Firebase using the Firebase credential: \n\n ```c++\n firebase::auth::Credential credential =\n firebase::auth::FacebookAuthProvider::GetCredential(access_token);\n firebase::Future\u003cfirebase::auth::AuthResult\u003e result =\n auth-\u003eSignInAndRetrieveDataWithCredential(credential);\n ```\n3. If your program has an update loop that runs regularly (say at 30 or 60 times per second), you can check the results once per update with `Auth::SignInAndRetrieveDataWithCredentialLastResult`: \n\n ```c++\n firebase::Future\u003cfirebase::auth::AuthResult\u003e result =\n auth-\u003eSignInAndRetrieveDataWithCredentialLastResult();\n if (result.status() == firebase::kFutureStatusComplete) {\n if (result.error() == firebase::auth::kAuthErrorNone) {\n firebase::auth::AuthResult auth_result = *result.result();\n printf(\"Sign in succeeded for `%s`\\n\",\n auth_result.user.display_name().c_str());\n } else {\n printf(\"Sign in failed with error '%s'\\n\", result.error_message());\n }\n }\n ```\n Or, if your program is event driven, you may prefer to [register a callback on the\n Future](#register_callback_on_future).\n\nRegister a callback on a Future Some programs have `Update` functions that are called 30 or 60 times per second. For example, many games follow this model. These programs can call the `LastResult` functions to poll asynchronous calls. However, if your program is event driven, you may prefer to register callback functions. A callback function is called upon completion of the Future. \n\n```c++\nvoid OnCreateCallback(const firebase::Future\u003cfirebase::auth::User*\u003e& result,\n void* user_data) {\n // The callback is called when the Future enters the `complete` state.\n assert(result.status() == firebase::kFutureStatusComplete);\n\n // Use `user_data` to pass-in program context, if you like.\n MyProgramContext* program_context = static_cast\u003cMyProgramContext*\u003e(user_data);\n\n // Important to handle both success and failure situations.\n if (result.error() == firebase::auth::kAuthErrorNone) {\n firebase::auth::User* user = *result.result();\n printf(\"Create user succeeded for email %s\\n\", user-\u003eemail().c_str());\n\n // Perform other actions on User, if you like.\n firebase::auth::User::UserProfile profile;\n profile.display_name = program_context-\u003edisplay_name;\n user-\u003eUpdateUserProfile(profile);\n\n } else {\n printf(\"Created user failed with error '%s'\\n\", result.error_message());\n }\n}\n\nvoid CreateUser(firebase::auth::Auth* auth) {\n // Callbacks work the same for any firebase::Future.\n firebase::Future\u003cfirebase::auth::AuthResult\u003e result =\n auth-\u003eCreateUserWithEmailAndPasswordLastResult();\n\n // `&my_program_context` is passed verbatim to OnCreateCallback().\n result.OnCompletion(OnCreateCallback, &my_program_context);\n}\n```\nThe callback function can also be a lambda, if you prefer. \n\n```c++\nvoid CreateUserUsingLambda(firebase::auth::Auth* auth) {\n // Callbacks work the same for any firebase::Future.\n firebase::Future\u003cfirebase::auth::AuthResult\u003e result =\n auth-\u003eCreateUserWithEmailAndPasswordLastResult();\n\n // The lambda has the same signature as the callback function.\n result.OnCompletion(\n [](const firebase::Future\u003cfirebase::auth::User*\u003e& result,\n void* user_data) {\n // `user_data` is the same as &my_program_context, below.\n // Note that we can't capture this value in the [] because std::function\n // is not supported by our minimum compiler spec (which is pre C++11).\n MyProgramContext* program_context =\n static_cast\u003cMyProgramContext*\u003e(user_data);\n\n // Process create user result...\n (void)program_context;\n },\n &my_program_context);\n}\n```\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```"]]