আপনি Firebase Authentication ব্যবহার করে একটি ব্যবহারকারীকে একটি লিঙ্ক সহ একটি ইমেল পাঠিয়ে সাইন ইন করতে পারেন, যেটিতে ক্লিক করে তারা সাইন ইন করতে পারে৷ প্রক্রিয়ায়, ব্যবহারকারীর ইমেল ঠিকানাও যাচাই করা হয়৷
ইমেলের মাধ্যমে সাইন ইন করার অনেক সুবিধা রয়েছে:
- কম ঘর্ষণ সাইন আপ এবং সাইন ইন.
- অ্যাপ্লিকেশানগুলিতে পাসওয়ার্ড পুনঃব্যবহারের কম ঝুঁকি, যা এমনকি ভাল-নির্বাচিত পাসওয়ার্ডগুলির নিরাপত্তাকে দুর্বল করতে পারে।
- একজন ব্যবহারকারীকে প্রমাণীকরণ করার ক্ষমতাও যাচাই করে যে ব্যবহারকারী একটি ইমেল ঠিকানার বৈধ মালিক।
- সাইন ইন করার জন্য একজন ব্যবহারকারীর শুধুমাত্র একটি অ্যাক্সেসযোগ্য ইমেল অ্যাকাউন্টের প্রয়োজন হয়৷ কোনও ফোন নম্বর বা সোশ্যাল মিডিয়া অ্যাকাউন্টের মালিকানার প্রয়োজন নেই৷
- একজন ব্যবহারকারী একটি পাসওয়ার্ড প্রদান (বা মনে রাখার) প্রয়োজন ছাড়াই নিরাপদে সাইন ইন করতে পারেন, যা একটি মোবাইল ডিভাইসে কষ্টকর হতে পারে।
- একটি বিদ্যমান ব্যবহারকারী যিনি পূর্বে একটি ইমেল শনাক্তকারী (পাসওয়ার্ড বা ফেডারেটেড) দিয়ে সাইন ইন করেছিলেন শুধুমাত্র ইমেল দিয়ে সাইন ইন করতে আপগ্রেড করা যেতে পারে৷ উদাহরণ স্বরূপ, যে ব্যবহারকারী তাদের পাসওয়ার্ড ভুলে গেছেন তারা তাদের পাসওয়ার্ড রিসেট না করেই সাইন ইন করতে পারবেন।
আপনি শুরু করার আগে
আপনার Android প্রকল্প সেট আপ করুন
যদি আপনি ইতিমধ্যেই না করে থাকেন তাহলে আপনার Android প্রকল্পে Firebase যোগ করুন ।
আপনার মডিউলে (অ্যাপ-লেভেল) গ্রেডল ফাইলে (সাধারণত
<project>/<app-module>/build.gradle.kts
বা<project>/<app-module>/build.gradle
), Android এর জন্য Firebase Authentication লাইব্রেরির জন্য নির্ভরতা যোগ করুন। আমরা লাইব্রেরি সংস্করণ নিয়ন্ত্রণ করতে Firebase Android BoM ব্যবহার করার পরামর্শ দিই।এছাড়াও, Firebase Authentication সেট আপ করার অংশ হিসাবে, আপনাকে আপনার অ্যাপে Google Play পরিষেবা SDK যোগ করতে হবে।
dependencies { // Import the BoM for the Firebase platform implementation(platform("com.google.firebase:firebase-bom:33.10.0")) // Add 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")
// Also add the dependency for the Google Play services library and specify its version implementation("com.google.android.gms:play-services-auth:21.3.0") }Firebase Android BoM ব্যবহার করে, আপনার অ্যাপ সবসময় Firebase Android লাইব্রেরির সামঞ্জস্যপূর্ণ সংস্করণ ব্যবহার করবে।
একটি কোটলিন-নির্দিষ্ট লাইব্রেরি মডিউল খুঁজছেন? অক্টোবর 2023 থেকে শুরু হচ্ছে ( Firebase BoM 32.5.0) , Kotlin এবং Java ডেভেলপাররা প্রধান লাইব্রেরি মডিউলের উপর নির্ভর করতে পারে (বিশদ বিবরণের জন্য, এই উদ্যোগ সম্পর্কে প্রায়শই জিজ্ঞাসিত প্রশ্ন দেখুন)।(বিকল্প) BoM ব্যবহার না করে Firebase লাইব্রেরি নির্ভরতা যোগ করুন
আপনি যদি Firebase BoM ব্যবহার না করা বেছে নেন, তাহলে আপনাকে অবশ্যই প্রতিটি Firebase লাইব্রেরি সংস্করণ তার নির্ভরতা লাইনে উল্লেখ করতে হবে।
মনে রাখবেন যে আপনি যদি আপনার অ্যাপে একাধিক ফায়ারবেস লাইব্রেরি ব্যবহার করেন, আমরা দৃঢ়ভাবে লাইব্রেরি সংস্করণগুলি পরিচালনা করতে BoM ব্যবহার করার পরামর্শ দিই, যা নিশ্চিত করে যে সমস্ত সংস্করণ সামঞ্জস্যপূর্ণ।
dependencies { // Add 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:23.2.0")
// Also add the dependency for the Google Play services library and specify its version implementation("com.google.android.gms:play-services-auth:21.3.0") }
আপনার Firebase প্রকল্পের জন্য ইমেল লিঙ্ক সাইন-ইন সক্ষম করুন
ইমেল লিঙ্ক দ্বারা ব্যবহারকারীদের সাইন ইন করতে, আপনাকে প্রথমে আপনার Firebase প্রকল্পের জন্য ইমেল প্রদানকারী এবং ইমেল লিঙ্ক সাইন-ইন পদ্ধতি সক্ষম করতে হবে:
- Firebase কনসোলে , Auth বিভাগটি খুলুন।
- সাইন ইন পদ্ধতি ট্যাবে, ইমেল/পাসওয়ার্ড প্রদানকারী সক্ষম করুন। নোট করুন যে ইমেল লিঙ্ক সাইন-ইন ব্যবহার করার জন্য ইমেল/পাসওয়ার্ড সাইন-ইন অবশ্যই সক্রিয় থাকতে হবে।
- একই বিভাগে, ইমেল লিঙ্ক (পাসওয়ার্ডবিহীন সাইন-ইন) সাইন-ইন পদ্ধতি সক্ষম করুন।
- Save এ ক্লিক করুন।
ব্যবহারকারীর ইমেল ঠিকানায় একটি প্রমাণীকরণ লিঙ্ক পাঠান
প্রমাণীকরণ প্রবাহ শুরু করার জন্য, ব্যবহারকারীকে একটি ইন্টারফেস সহ উপস্থাপন করুন যা ব্যবহারকারীকে তাদের ইমেল ঠিকানা প্রদান করতে অনুরোধ করে এবং তারপরে sendSignInLinkToEmail
কল করে অনুরোধ করে যে Firebase ব্যবহারকারীর ইমেলে প্রমাণীকরণ লিঙ্কটি পাঠায়।
ActionCodeSettings অবজেক্ট তৈরি করুন, যা Firebase-কে ইমেল লিঙ্ক কীভাবে তৈরি করতে হয় তার নির্দেশাবলী প্রদান করে। নিম্নলিখিত ক্ষেত্র সেট করুন:
-
url
: এম্বেড করার গভীর লিঙ্ক এবং যেকোন অতিরিক্ত অবস্থা পাস করতে হবে। লিঙ্কের ডোমেনটিকে অনুমোদিত ডোমেনের Firebase কনসোলের তালিকায় সাদা তালিকাভুক্ত করতে হবে, যা সাইন-ইন পদ্ধতি ট্যাবে গিয়ে (প্রমাণিকরণ -> সাইন-ইন পদ্ধতি) পাওয়া যাবে। লিঙ্কটি ব্যবহারকারীকে এই URL-এ পুনঃনির্দেশ করবে যদি অ্যাপটি তাদের ডিভাইসে ইনস্টল করা না থাকে এবং অ্যাপটি ইনস্টল করা সম্ভব না হয়। -
androidPackageName
এবংiOSBundleId
: Firebase Authentication এটি নির্ধারণ করতে সাহায্য করে যে এটি একটি শুধুমাত্র-ওয়েব বা মোবাইল লিঙ্ক তৈরি করবে যা একটি Android বা Apple ডিভাইসে খোলা হবে। -
handleCodeInApp
: সত্যে সেট করুন। সাইন-ইন অপারেশনটি সর্বদা অ্যাপে সম্পূর্ণ করতে হবে অন্যান্য ব্যান্ড ইমেল অ্যাকশনের বিপরীতে (পাসওয়ার্ড রিসেট এবং ইমেল যাচাইকরণ)। এর কারণ হল, প্রবাহের শেষে, ব্যবহারকারী সাইন ইন করবেন বলে আশা করা হচ্ছে এবং অ্যাপের মধ্যে তাদের প্রমাণীকরণ স্থিতি বজায় থাকবে। -
linkDomain
: যখন একটি প্রকল্পের জন্য কাস্টম Hosting লিঙ্ক ডোমেনগুলি সংজ্ঞায়িত করা হয়, নির্দিষ্ট মোবাইল অ্যাপ দ্বারা লিঙ্কটি খোলার সময় কোনটি ব্যবহার করতে হবে তা নির্দিষ্ট করুন৷ অন্যথায়, ডিফল্ট ডোমেন স্বয়ংক্রিয়ভাবে নির্বাচিত হয় (উদাহরণস্বরূপ,PROJECT_ID .firebaseapp.com
)। dynamicLinkDomain
: অবচয়। এই প্যারামিটার নির্দিষ্ট করবেন না।
val actionCodeSettings = actionCodeSettings { // URL you want to redirect back to. The domain (www.example.com) for this // URL must be whitelisted in the Firebase Console. url = "https://www.example.com/finishSignUp?cartId=1234" // This must be true handleCodeInApp = true setIOSBundleId("com.example.ios") setAndroidPackageName( "com.example.android", true, // installIfNotAvailable "12", // minimumVersion ) }
ActionCodeSettings actionCodeSettings = ActionCodeSettings.newBuilder() // URL you want to redirect back to. The domain (www.example.com) for this // URL must be whitelisted in the Firebase Console. .setUrl("https://www.example.com/finishSignUp?cartId=1234") // This must be true .setHandleCodeInApp(true) .setIOSBundleId("com.example.ios") .setAndroidPackageName( "com.example.android", true, /* installIfNotAvailable */ "12" /* minimumVersion */) .build();
ActionCodeSettings সম্পর্কে আরো জানতে, Email Actions বিভাগে পাসিং স্টেট পড়ুন। -
ব্যবহারকারীকে তাদের ইমেলের জন্য জিজ্ঞাসা করুন। ব্যবহারকারীর ইমেলে প্রমাণীকরণ লিঙ্কটি পাঠান এবং ব্যবহারকারীর ইমেলটি সংরক্ষণ করুন যদি ব্যবহারকারী একই ডিভাইসে ইমেল সাইন-ইন সম্পূর্ণ করেন। Firebase.auth.sendSignInLinkToEmail(email, actionCodeSettings) .addOnCompleteListener { task -> if (task.isSuccessful) { Log.d(TAG, "Email sent.") } }
FirebaseAuth auth = FirebaseAuth.getInstance(); auth.sendSignInLinkToEmail(email, actionCodeSettings) .addOnCompleteListener(new OnCompleteListener<Void>() { @Override public void onComplete(@NonNull Task<Void> task) { if (task.isSuccessful()) { Log.d(TAG, "Email sent."); } } });
ইমেল লিঙ্ক দিয়ে সাইন ইন সম্পূর্ণ করুন
নিরাপত্তা উদ্বেগ
একটি Android অ্যাপে সাইন-ইন সম্পূর্ণ করা হচ্ছে
Firebase Hosting কনফিগার করুন
Firebase Hosting ডোমেন কনফিগার করুন: Firebase কনসোলে, হোস্টিং বিভাগটি খুলুন। আপনি যদি মোবাইল অ্যাপ্লিকেশনগুলিতে খোলা ইমেল লিঙ্কের জন্য ডিফল্ট ডোমেন ব্যবহার করতে চান, তাহলে আপনার ডিফল্ট সাইটে যান এবং আপনার ডিফল্ট Hosting ডোমেনটি নোট করুন৷ একটি ডিফল্ট Hosting ডোমেন সাধারণত এই মত দেখায়: PROJECT_ID .firebaseapp.com
।আপনি যখন ইনকামিং লিঙ্কটিকে আটকাতে আপনার অ্যাপটি কনফিগার করবেন তখন আপনার এই মানটির প্রয়োজন হবে৷ আপনি যদি ইমেল লিঙ্কের জন্য একটি কাস্টম ডোমেন ব্যবহার করতে চান, আপনি Firebase Hosting সাথে একটি নিবন্ধন করতে পারেন এবং লিঙ্কের ডোমেনের জন্য এটি ব্যবহার করতে পারেন।
অ্যান্ড্রয়েড অ্যাপ্লিকেশন কনফিগার করা: আপনার অ্যান্ড্রয়েড অ্যাপ্লিকেশন থেকে এই লিঙ্কগুলি পরিচালনা করার জন্য, আপনার অ্যাপের প্যাকেজের নাম Firebase কনসোল প্রকল্প সেটিংসে নির্দিষ্ট করা প্রয়োজন৷ এছাড়াও, আবেদনের শংসাপত্রের SHA-1 এবং SHA-256 প্রদান করতে হবে। আপনি যদি এই লিঙ্কগুলিকে একটি নির্দিষ্ট কার্যকলাপে পুনঃনির্দেশ করতে চান তবে আপনাকে আপনার AndroidManifest.xml
ফাইলে একটি অভিপ্রায় ফিল্টার কনফিগার করতে হবে। অভিপ্রায় ফিল্টারটি আপনার ডোমেনের ইমেল লিঙ্কগুলিকে ধরতে হবে।AndroidManifest.xml
এ:<intent-filter android:autoVerify="true"> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.BROWSABLE" /> <category android:name="android.intent.category.DEFAULT" /> <data android:scheme="https" android:host="<PROJECT_ID>.firebaseapp.com or your custom domain" android:pathPrefix="/__/auth/links" /> </intent-filter>
ব্যবহারকারীরা যখন
/__/auth/links
পাথ এবং আপনার নির্দিষ্ট করা স্কিম এবং হোস্টের সাথে একটি হোস্টিং লিঙ্ক খোলে, তখন আপনার অ্যাপটি লিঙ্কটি পরিচালনা করতে এই উদ্দেশ্য ফিল্টার দিয়ে কার্যকলাপ শুরু করবে।
লিঙ্ক যাচাই করুন এবং সাইন ইন করুন
val auth = Firebase.auth val intent = intent val emailLink = intent.data.toString() // Confirm the link is a sign-in with email link. if (auth.isSignInWithEmailLink(emailLink)) { // Retrieve this from wherever you stored it val email = "someemail@domain.com" // The client SDK will parse the code from the link for you. auth.signInWithEmailLink(email, emailLink) .addOnCompleteListener { task -> if (task.isSuccessful) { Log.d(TAG, "Successfully signed in with email link!") val result = task.result // You can access the new user via result.getUser() // Additional user info profile *not* available via: // result.getAdditionalUserInfo().getProfile() == null // You can check if the user is new or existing: // result.getAdditionalUserInfo().isNewUser() } else { Log.e(TAG, "Error signing in with email link", task.exception) } } }
FirebaseAuth auth = FirebaseAuth.getInstance(); Intent intent = getIntent(); String emailLink = intent.getData().toString(); // Confirm the link is a sign-in with email link. if (auth.isSignInWithEmailLink(emailLink)) { // Retrieve this from wherever you stored it String email = "someemail@domain.com"; // The client SDK will parse the code from the link for you. auth.signInWithEmailLink(email, emailLink) .addOnCompleteListener(new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { if (task.isSuccessful()) { Log.d(TAG, "Successfully signed in with email link!"); AuthResult result = task.getResult(); // You can access the new user via result.getUser() // Additional user info profile *not* available via: // result.getAdditionalUserInfo().getProfile() == null // You can check if the user is new or existing: // result.getAdditionalUserInfo().isNewUser() } else { Log.e(TAG, "Error signing in with email link", task.getException()); } } }); }
ইমেল লিঙ্কের সাথে লিঙ্ক করা/পুনরায় প্রমাণীকরণ
// Construct the email link credential from the current URL. val credential = EmailAuthProvider.getCredentialWithLink(email, emailLink) // Link the credential to the current user. Firebase.auth.currentUser!!.linkWithCredential(credential) .addOnCompleteListener { task -> if (task.isSuccessful) { Log.d(TAG, "Successfully linked emailLink credential!") val result = task.result // You can access the new user via result.getUser() // Additional user info profile *not* available via: // result.getAdditionalUserInfo().getProfile() == null // You can check if the user is new or existing: // result.getAdditionalUserInfo().isNewUser() } else { Log.e(TAG, "Error linking emailLink credential", task.exception) } }
// Construct the email link credential from the current URL. AuthCredential credential = EmailAuthProvider.getCredentialWithLink(email, emailLink); // Link the credential to the current user. auth.getCurrentUser().linkWithCredential(credential) .addOnCompleteListener(new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { if (task.isSuccessful()) { Log.d(TAG, "Successfully linked emailLink credential!"); AuthResult result = task.getResult(); // You can access the new user via result.getUser() // Additional user info profile *not* available via: // result.getAdditionalUserInfo().getProfile() == null // You can check if the user is new or existing: // result.getAdditionalUserInfo().isNewUser() } else { Log.e(TAG, "Error linking emailLink credential", task.getException()); } } });
// Construct the email link credential from the current URL. val credential = EmailAuthProvider.getCredentialWithLink(email, emailLink) // Re-authenticate the user with this credential. Firebase.auth.currentUser!!.reauthenticateAndRetrieveData(credential) .addOnCompleteListener { task -> if (task.isSuccessful) { // User is now successfully reauthenticated } else { Log.e(TAG, "Error reauthenticating", task.exception) } }
// Construct the email link credential from the current URL. AuthCredential credential = EmailAuthProvider.getCredentialWithLink(email, emailLink); // Re-authenticate the user with this credential. auth.getCurrentUser().reauthenticateAndRetrieveData(credential) .addOnCompleteListener(new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { if (task.isSuccessful()) { // User is now successfully reauthenticated } else { Log.e(TAG, "Error reauthenticating", task.getException()); } } });
বাতিল করা হয়েছে: Firebase Dynamic Links ভিত্তিক যাচাইকরণ
অপ্রচলিত: ইমেল লিঙ্ক থেকে ইমেল-পাসওয়ার্ডের পার্থক্য
fetchSignInMethodsForEmail()
পদ্ধতিটি নিষ্ক্রিয় করে, যা আমরা পূর্বে শনাক্তকারী-প্রথম প্রবাহ বাস্তবায়নের জন্য সুপারিশ করেছিলাম।
পরবর্তী পদক্ষেপ
আপনার অ্যাপে, আপনি FirebaseUser
অবজেক্ট থেকে ব্যবহারকারীর মৌলিক প্রোফাইল তথ্য পেতে পারেন। ব্যবহারকারীদের পরিচালনা দেখুন।আপনার Firebase Realtime Database এবং Cloud Storage সুরক্ষা নিয়মে , আপনি auth
ভেরিয়েবল থেকে সাইন-ইন করা ব্যবহারকারীর অনন্য ব্যবহারকারী আইডি পেতে পারেন এবং ব্যবহারকারী কোন ডেটা অ্যাক্সেস করতে পারে তা নিয়ন্ত্রণ করতে এটি ব্যবহার করতে পারেন।
signOut
কল করুন:
Firebase.auth.signOut()
FirebaseAuth.getInstance().signOut();