2022'de desteği sonlandırılan Şifreler için Smart Lock, Google Play Hizmetleri Auth SDK'sından (com.google.android.gms:play-services-auth
) kaldırıldı. Mevcut entegrasyonları etkileyebilecek önemli değişikliklerin en aza indirilmesi için Play Store'daki tüm mevcut uygulamalarda Smart Lock özellikleri gerektiği gibi çalışmaya devam edecektir. Güncellenmiş SDK (com.google.android.gms:play-services-auth:21.0.0
) ile derlenen yeni uygulama sürümleri artık Şifreler için Smart Lock API'ye erişemediğinden başarılı bir şekilde derlenemez. Tüm geliştiriciler, Android projelerini en kısa zamanda taşıyarak Kimlik Bilgisi Yöneticisi'ni kullanmalıdır.
Credential Manager API'ye geçiş yapmanın avantajları
Kimlik Bilgisi Yöneticisi, kullanıcılarınız için kimlik doğrulama deneyimini iyileştirerek modern özelliklere ve uygulamalara destek sağlayan basit, birleşik bir API sunar:
- Kimlik Bilgisi Yöneticisi, şifre kaydetme ve kimlik doğrulamayı tam olarak destekler. Bu, uygulamanız Smart Lock'tan Kimlik Bilgisi Yöneticisi'ne taşınırken kullanıcılarınız için herhangi bir kesinti olmayacağı anlamına gelir.
- Kimlik Bilgisi Yöneticisi, geçiş anahtarları ve Google ile oturum açma gibi birleşik oturum açma yöntemleri de dahil olmak üzere birden fazla oturum açma yöntemini destekler. Bu sayede, güvenliği artırabilir ve gelecekte bu yöntemleri desteklemeyi planlıyorsanız dönüşümü etkinleştirebilirsiniz.
- Android 14'ten itibaren Kimlik Bilgisi Yöneticisi, üçüncü taraf şifre ve geçiş anahtarı sağlayıcılarını destekler.
- Kimlik Bilgisi Yöneticisi, tüm kimlik doğrulama yöntemlerinde tutarlı ve birleşik bir kullanıcı deneyimi sunar.
Taşıma seçenekleri:
Kullanım alanına | Öneri |
---|---|
Şifreyi kaydetme ve kayıtlı şifreyle oturum açma | Kimlik Bilgisi Yöneticisi ile kullanıcınızın oturumunu açma kılavuzundaki şifre seçeneğini kullanın. Şifre kaydetme ve kimlik doğrulamayla ilgili ayrıntılı adımlar aşağıda açıklanmıştır. |
Google ile oturum aç | Kimlik Bilgisi Yöneticisi'ni Google ile oturum açma ile entegre etme kılavuzunu uygulayın. |
Kullanıcılara telefon numarası ipucunu gösterme | Google Identity Services'deki Telefon Numarası İpucu API'sini kullanın. |
Kimlik Bilgisi Yöneticisi'ni kullanarak şifrelerle oturum açma
Kimlik Bilgisi Yöneticisi API'sini kullanmak için Kimlik Bilgisi Yöneticisi kılavuzunun ön koşullar bölümünde belirtilen adımları tamamlayın ve aşağıdakileri yaptığınızdan emin olun:
- Zorunlu bağımlılıkları ekleme
- ProGuard dosyasında sınıfları koruma
- Dijital Öğe Bağlantıları için destek ekleyin (Şifreler için Smart Lock'u kullanıyorsanız bu adım zaten uygulanmış olmalıdır)
- Kimlik Bilgileri Yöneticisi'ni yapılandırma
- Kimlik bilgisi alanlarını belirtme
- Kullanıcı şifresini kaydetme
Kayıtlı şifrelerle oturum açma
Kullanıcının hesabıyla ilişkili şifre seçeneklerini almak için aşağıdaki adımları uygulayın:
1. Şifre ve kimlik doğrulama seçeneğini başlatma
// Retrieves the user's saved password for your app from their
// password provider.
val getPasswordOption = GetPasswordOption()
2. Oturum açma isteğini oluşturmak için önceki adımdan alınan seçenekleri kullanın
val getCredRequest = GetCredentialRequest(
listOf(getPasswordOption)
)
3. Oturum açma akışını başlatma
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}")
}
}
}
Ek kaynaklar
- Kimlik Bilgisi Yöneticisi örnek referansı
- Kimlik Bilgisi Yöneticisi codelab'i
- Kimlik Bilgisi Yöneticisi ile kullanıcınızda oturum açma