তুমি শুরু করার আগে
- যদি আপনি ইতিমধ্যেই না করে থাকেন তাহলে আপনার Android প্রকল্পে Firebase যোগ করুন ।
- Firebase Android BoM ব্যবহার করে, আপনার মডিউল (অ্যাপ-লেভেল) গ্রেডল ফাইলে (সাধারণত
app/build.gradle
) ফায়ারবেস প্রমাণীকরণ অ্যান্ড্রয়েড লাইব্রেরির জন্য নির্ভরতা ঘোষণা করুন।Java
dependencies { // Import the BoM for the Firebase platform implementation platform('com.google.firebase:firebase-bom:30.2.0') // Declare the dependency for the Firebase Authentication library // When using the BoM, you don't specify versions in Firebase library dependencies implementation 'com.google.firebase:firebase-auth' }
Firebase Android BoM ব্যবহার করে, আপনার অ্যাপ সবসময় Firebase Android লাইব্রেরির সামঞ্জস্যপূর্ণ সংস্করণ ব্যবহার করবে।
(বিকল্প) BoM ব্যবহার না করে Firebase লাইব্রেরি নির্ভরতা ঘোষণা করুন
আপনি যদি Firebase BoM ব্যবহার না করা বেছে নেন, তাহলে আপনাকে অবশ্যই প্রতিটি Firebase লাইব্রেরি সংস্করণ তার নির্ভরতা লাইনে উল্লেখ করতে হবে।
মনে রাখবেন যে আপনি যদি আপনার অ্যাপে একাধিক Firebase লাইব্রেরি ব্যবহার করেন, তাহলে আমরা লাইব্রেরি সংস্করণগুলি পরিচালনা করতে BoM ব্যবহার করার সুপারিশ করি, যা নিশ্চিত করে যে সমস্ত সংস্করণ সামঞ্জস্যপূর্ণ।
dependencies { // Declare the dependency for the Firebase Authentication library // When NOT using the BoM, you must specify versions in Firebase library dependencies implementation 'com.google.firebase:firebase-auth:21.0.6' }
Kotlin+KTX
dependencies { // Import the BoM for the Firebase platform implementation platform('com.google.firebase:firebase-bom:30.2.0') // Declare the dependency for the Firebase Authentication library // When using the BoM, you don't specify versions in Firebase library dependencies implementation 'com.google.firebase:firebase-auth-ktx' }
Firebase Android BoM ব্যবহার করে, আপনার অ্যাপ সবসময় Firebase Android লাইব্রেরির সামঞ্জস্যপূর্ণ সংস্করণ ব্যবহার করবে।
(বিকল্প) BoM ব্যবহার না করে Firebase লাইব্রেরি নির্ভরতা ঘোষণা করুন
আপনি যদি Firebase BoM ব্যবহার না করা বেছে নেন, তাহলে আপনাকে অবশ্যই প্রতিটি Firebase লাইব্রেরি সংস্করণ তার নির্ভরতা লাইনে উল্লেখ করতে হবে।
মনে রাখবেন যে আপনি যদি আপনার অ্যাপে একাধিক Firebase লাইব্রেরি ব্যবহার করেন, তাহলে আমরা লাইব্রেরি সংস্করণগুলি পরিচালনা করতে BoM ব্যবহার করার সুপারিশ করি, যা নিশ্চিত করে যে সমস্ত সংস্করণ সামঞ্জস্যপূর্ণ।
dependencies { // Declare the dependency for the Firebase Authentication library // When NOT using the BoM, you must specify versions in Firebase library dependencies implementation 'com.google.firebase:firebase-auth-ktx:21.0.6' }
- আপনার প্রকল্পের সার্ভার কী পান:
- আপনার প্রকল্পের সেটিংসে পরিষেবা অ্যাকাউন্ট পৃষ্ঠাতে যান।
- সার্ভিস অ্যাকাউন্ট পৃষ্ঠার ফায়ারবেস অ্যাডমিন SDK বিভাগের নীচে জেনারেট নিউ প্রাইভেট কী ক্লিক করুন।
- নতুন পরিষেবা অ্যাকাউন্টের পাবলিক/প্রাইভেট কী জোড়া আপনার কম্পিউটারে স্বয়ংক্রিয়ভাবে সংরক্ষিত হয়। এই ফাইলটি আপনার প্রমাণীকরণ সার্ভারে অনুলিপি করুন।
Firebase দিয়ে প্রমাণীকরণ করুন
- আপনার সাইন-ইন কার্যকলাপের
onCreate
পদ্ধতিতে,FirebaseAuth
অবজেক্টের ভাগ করা উদাহরণ পান:Java
private FirebaseAuth mAuth; // ... // Initialize Firebase Auth mAuth = FirebaseAuth.getInstance();
Kotlin+KTX
private lateinit var auth: FirebaseAuth // ... // Initialize Firebase Auth auth = Firebase.auth
- আপনার ক্রিয়াকলাপ শুরু করার সময়, ব্যবহারকারী বর্তমানে সাইন ইন করেছেন কিনা তা পরীক্ষা করে দেখুন:
Java
@Override public void onStart() { super.onStart(); // Check if user is signed in (non-null) and update UI accordingly. FirebaseUser currentUser = mAuth.getCurrentUser(); updateUI(currentUser); }
Kotlin+KTX
public override fun onStart() { super.onStart() // Check if user is signed in (non-null) and update UI accordingly. val currentUser = auth.currentUser updateUI(currentUser) }
- যখন ব্যবহারকারীরা আপনার অ্যাপে সাইন ইন করেন, তখন তাদের সাইন-ইন শংসাপত্র (উদাহরণস্বরূপ, তাদের ব্যবহারকারীর নাম এবং পাসওয়ার্ড) আপনার প্রমাণীকরণ সার্ভারে পাঠান। আপনার সার্ভার শংসাপত্রগুলি পরীক্ষা করে এবং একটি কাস্টম টোকেন প্রদান করে যদি সেগুলি বৈধ হয়৷
- আপনি আপনার প্রমাণীকরণ সার্ভার থেকে কাস্টম টোকেন পাওয়ার পরে, ব্যবহারকারীকে সাইন ইন করতে
signInWithCustomToken
এ পাস করুন:সাইন-ইন সফল হলে,Java
mAuth.signInWithCustomToken(mCustomToken) .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { if (task.isSuccessful()) { // Sign in success, update UI with the signed-in user's information Log.d(TAG, "signInWithCustomToken:success"); FirebaseUser user = mAuth.getCurrentUser(); updateUI(user); } else { // If sign in fails, display a message to the user. Log.w(TAG, "signInWithCustomToken:failure", task.getException()); Toast.makeText(CustomAuthActivity.this, "Authentication failed.", Toast.LENGTH_SHORT).show(); updateUI(null); } } });
Kotlin+KTX
customToken?.let { auth.signInWithCustomToken(it) .addOnCompleteListener(this) { task -> if (task.isSuccessful) { // Sign in success, update UI with the signed-in user's information Log.d(TAG, "signInWithCustomToken:success") val user = auth.currentUser updateUI(user) } else { // If sign in fails, display a message to the user. Log.w(TAG, "signInWithCustomToken:failure", task.exception) Toast.makeText(baseContext, "Authentication failed.", Toast.LENGTH_SHORT).show() updateUI(null) } } }
AuthStateListener
আপনি ব্যবহারকারীর অ্যাকাউন্ট ডেটা পেতেgetCurrentUser
পদ্ধতি ব্যবহার করতে পারেন।
পরবর্তী পদক্ষেপ
একজন ব্যবহারকারী প্রথমবার সাইন ইন করার পরে, একটি নতুন ব্যবহারকারীর অ্যাকাউন্ট তৈরি করা হয় এবং শংসাপত্রগুলির সাথে লিঙ্ক করা হয়—অর্থাৎ, ব্যবহারকারীর নাম এবং পাসওয়ার্ড, ফোন নম্বর, বা প্রমাণ প্রদানকারীর তথ্য — ব্যবহারকারী সাইন ইন করেছেন। এই নতুন অ্যাকাউন্টটি আপনার ফায়ারবেস প্রকল্পের অংশ হিসাবে সংরক্ষণ করা হয়েছে এবং ব্যবহারকারী কীভাবে সাইন ইন করুন না কেন, আপনার প্রকল্পের প্রতিটি অ্যাপ জুড়ে একজন ব্যবহারকারীকে শনাক্ত করতে ব্যবহার করা যেতে পারে।
আপনার অ্যাপে, আপনি
FirebaseUser
অবজেক্ট থেকে ব্যবহারকারীর মৌলিক প্রোফাইল তথ্য পেতে পারেন। ব্যবহারকারীদের পরিচালনা দেখুন।আপনার ফায়ারবেস রিয়েলটাইম ডেটাবেস এবং ক্লাউড স্টোরেজ সুরক্ষা নিয়মে , আপনি
auth
ভেরিয়েবল থেকে সাইন-ইন করা ব্যবহারকারীর অনন্য ব্যবহারকারী আইডি পেতে পারেন এবং ব্যবহারকারী কোন ডেটা অ্যাক্সেস করতে পারে তা নিয়ন্ত্রণ করতে এটি ব্যবহার করতে পারেন।
একজন ব্যবহারকারীকে সাইন আউট করতে,
signOut
কল করুন:Java
FirebaseAuth.getInstance().signOut();
Kotlin+KTX
Firebase.auth.signOut()
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2022-07-06 UTC.
[{ "type": "thumb-down", "id": "missingTheInformationINeed", "label":"এতে আমার প্রয়োজনীয় তথ্য নেই" },{ "type": "thumb-down", "id": "tooComplicatedTooManySteps", "label":"খুব জটিল / অনেক ধাপ" },{ "type": "thumb-down", "id": "outOfDate", "label":"পুরনো" },{ "type": "thumb-down", "id": "translationIssue", "label":"অনুবাদ সংক্রান্ত সমস্যা" },{ "type": "thumb-down", "id": "samplesCodeIssue", "label":"নমুনা / কোড সংক্রান্ত সমস্যা" },{ "type": "thumb-down", "id": "otherDown", "label":"অন্যান্য" }] [{ "type": "thumb-up", "id": "easyToUnderstand", "label":"সহজে বোঝা যায়" },{ "type": "thumb-up", "id": "solvedMyProblem", "label":"আমার সমস্যার সমাধান হয়েছে" },{ "type": "thumb-up", "id": "otherUp", "label":"অন্যান্য" }] - আপনার প্রকল্পের সার্ভার কী পান: