पासवर्ड के लिए स्मार्ट लॉक की सुविधा को 2022 में बंद कर दिया गया था. अब इसे Google Play services Auth SDK
(com.google.android.gms:play-services-auth
) से हटा दिया गया है. मौजूदा इंटिग्रेशन पर असर डालने वाले बदलावों को कम करने के लिए, Play Store में मौजूद सभी ऐप्लिकेशन के लिए स्मार्ट लॉक की सुविधाएं सही तरीके से काम करती रहेंगी. अपडेट किए गए SDK टूल (com.google.android.gms:play-services-auth:21.0.0
) के साथ कंपाइल किए गए ऐप्लिकेशन के नए वर्शन, अब पासवर्ड के लिए स्मार्ट लॉक एपीआई को ऐक्सेस नहीं कर सकते. साथ ही, इन ऐप्लिकेशन से साइन इन करने का अनुरोध भी पूरा नहीं किया जा सकेगा. सभी डेवलपर को जल्द से जल्द Credential Manager का इस्तेमाल करने के लिए, अपने Android प्रोजेक्ट माइग्रेट करने चाहिए.
Credential Manager API पर माइग्रेट करने के फ़ायदे
क्रेडेंशियल मैनेजर एक आसान और यूनिफ़ाइड API उपलब्ध कराता है. इससे, उपयोगकर्ताओं के लिए पुष्टि करने के अनुभव को बेहतर बनाने के साथ-साथ, आधुनिक सुविधाओं और तरीकों के लिए सहायता मिलती है:
- Credential Manager, पासवर्ड सेव करने और पुष्टि करने की सुविधा पूरी तरह से इस्तेमाल करता है. इसका मतलब है कि आपका ऐप्लिकेशन, स्मार्ट लॉक से क्रेडेंशियल मैनेजर पर माइग्रेट होने पर, आपके उपयोगकर्ताओं को कोई रुकावट नहीं होगी.
- Credential Manager, साइन इन करने के कई तरीकों के साथ काम करता है. इनमें पासकी और Google से साइन इन करें जैसे फ़ेडरेटेड साइन इन के तरीके शामिल हैं. इससे सुरक्षा बढ़ती है और अगर आने वाले समय में इनमें से किसी एक तरीके का इस्तेमाल करना है, तो कन्वर्ज़न की सुविधा चालू की जा सकती है.
- Android 14 से, क्रेडेंशियल मैनेजर में तीसरे पक्ष के पासवर्ड और पासकी की सुविधाएं काम करती हैं.
- क्रेडेंशियल मैनेजर, पुष्टि करने के सभी तरीकों के लिए एक जैसा और यूनिफ़ाइड उपयोगकर्ता अनुभव देता है.
माइग्रेशन के विकल्प:
इस्तेमाल का उदाहरण | सुझाव |
---|---|
पासवर्ड सेव करना और सेव किए गए पासवर्ड से साइन इन करना | क्रेडेंशियल मैनेजर की मदद से उपयोगकर्ता को साइन इन कराने के बारे में बताने वाली गाइड में, पासवर्ड के विकल्प का इस्तेमाल करें. पासवर्ड सेव करने और पुष्टि करने के बारे में ज़्यादा जानकारी, यहां दी गई है. |
Google से साइन इन करें | Credential Manager को 'Google से साइन इन करें' के साथ इंटिग्रेट करने के लिए, गाइड में दिया गया तरीका अपनाएं. |
उपयोगकर्ताओं को फ़ोन नंबर का हिंट दिखाना | Google Identity Services के फ़ोन नंबर के सुझाव वाले एपीआई का इस्तेमाल करें. |
क्रेडेंशियल मैनेजर का इस्तेमाल करके पासवर्ड से साइन इन करना
Credential Manager API का इस्तेमाल करने के लिए, Credential Manager की गाइड के ज़रूरी शर्तें सेक्शन में दिया गया तरीका अपनाएं. साथ ही, पक्का करें कि आपने ये काम किए हों:
- ज़रूरी डिपेंडेंसी जोड़ना
- ProGuard फ़ाइल में क्लास को सुरक्षित रखना
- डिजिटल एसेट के लिंक के लिए सहायता जोड़ें (अगर पासवर्ड के लिए Smart Lock का इस्तेमाल किया जा रहा है, तो यह चरण पहले से लागू होना चाहिए)
- Credential Manager को कॉन्फ़िगर करना
- क्रेडेंशियल फ़ील्ड दिखाना
- उपयोगकर्ता का पासवर्ड सेव करना
सेव किए गए पासवर्ड से साइन इन करना
उपयोगकर्ता के खाते से जुड़े पासवर्ड के विकल्प वापस पाने के लिए, यह तरीका अपनाएं:
1. पासवर्ड और पुष्टि करने के विकल्प को शुरू करना
// Retrieves the user's saved password for your app from their
// password provider.
val getPasswordOption = GetPasswordOption()
2. साइन-इन करने का अनुरोध बनाने के लिए, पिछले चरण में मिले विकल्पों का इस्तेमाल करें
val getCredRequest = GetCredentialRequest(
listOf(getPasswordOption)
)
3. साइन-इन फ़्लो लॉन्च करना
fun launchSignInFlow() {
coroutineScope.launch {
try {
// Attempt to retrieve the credential from the Credential Manager.
val result = credentialManager.getCredential(
// Use an activity-based context to avoid undefined system UI
// launching behavior.
context = activityContext,
request = getCredRequest
)
// Process the successfully retrieved credential.
handleSignIn(result)
} catch (e: GetCredentialException) {
// Handle any errors that occur during the credential retrieval
// process.
handleFailure(e)
}
}
}
private fun handleSignIn(result: GetCredentialResponse) {
// Extract the credential from the response.
val credential = result.credential
// Determine the type of credential and handle it accordingly.
when (credential) {
is PasswordCredential -> {
val username = credential.id
val password = credential.password
// Use the extracted username and password to perform
// authentication.
}
else -> {
// Handle unrecognized credential types.
Log.e(TAG, "Unexpected type of credential")
}
}
}
private fun handleFailure(e: GetCredentialException) {
// Handle specific credential retrieval errors.
when (e) {
is GetCredentialCancellationException -> {
/* This exception is thrown when the user intentionally cancels
the credential retrieval operation. Update the application's state
accordingly. */
}
is GetCredentialCustomException -> {
/* This exception is thrown when a custom error occurs during the
credential retrieval flow. Refer to the documentation of the
third-party SDK used to create the GetCredentialRequest for
handling this exception. */
}
is GetCredentialInterruptedException -> {
/* This exception is thrown when an interruption occurs during the
credential retrieval flow. Determine whether to retry the
operation or proceed with an alternative authentication method. */
}
is GetCredentialProviderConfigurationException -> {
/* This exception is thrown when there is a mismatch in
configurations for the credential provider. Verify that the
provider dependency is included in the manifest and that the
required system services are enabled. */
}
is GetCredentialUnknownException -> {
/* This exception is thrown when the credential retrieval
operation fails without providing any additional details. Handle
the error appropriately based on the application's context. */
}
is GetCredentialUnsupportedException -> {
/* This exception is thrown when the device does not support the
Credential Manager feature. Inform the user that credential-based
authentication is unavailable and guide them to an alternative
authentication method. */
}
is NoCredentialException -> {
/* This exception is thrown when there are no viable credentials
available for the user. Prompt the user to sign up for an account
or provide an alternative authentication method. Upon successful
authentication, store the login information using
androidx.credentials.CredentialManager.createCredential to
facilitate easier sign-in the next time. */
}
else -> {
// Handle unexpected exceptions.
Log.w(TAG, "Unexpected exception type: ${e::class.java.name}")
}
}
}
अन्य संसाधन
- Credential Manager का सैंपल रेफ़रंस
- Credential Manager का कोडलैब
- Credential Manager की मदद से अपने उपयोगकर्ता को साइन इन कराना