Status Update
Comments
bl...@google.com <bl...@google.com> #2
jb...@google.com <jb...@google.com> #3
The error you posted state "activity is cancelled by the user". This implies the request was cancelled somehow during the request.
Can you grab a bugreport and attach it to this bug?
sg...@google.com <sg...@google.com> #4
can you please grab a bugreport and attached with this thread? Also could you share how did you request the sign-in with google option? parameters?
pr...@lycorp.co.jp <pr...@lycorp.co.jp> #5
pr...@lycorp.co.jp <pr...@lycorp.co.jp> #6 Restricted+
pr...@lycorp.co.jp <pr...@lycorp.co.jp> #7
Please check attached code sample.
I already requested user to attach bug report but I can't ensure about it.
sg...@google.com <sg...@google.com> #8
None of the attachment works unfortunately. For code snippet, can you simply copy and paste the core piece here.
Bugreport will be super helpful in understanding the root cause. but it seems like you're not able to reproduce this issue, and it only happen to this specific user?
pr...@lycorp.co.jp <pr...@lycorp.co.jp> #9
Please check code snippet as follows,
class GoogleAccount(private val listener: Listener) {
fun login(activity: FragmentActivity, private val coroutineScope: CoroutineScope) {
val credentialManager = CredentialManager.create(activity)
coroutineScope.launch {
val result = signInWithGoogle(activity, credentialManager, getCredentialRequest())
val finalResult = handleResultAndRetryIfRequired(activity, credentialManager, result)
when (finalResult) {
Result.Cancel -> listener.onCancel()
is Result.Failure -> {
listener.onCancel()
}
is Result.Success -> listener.onSuccess(finalResult.idToken)
}
}
}
private suspend fun signInWithGoogle(
activity: FragmentActivity,
credentialManager: CredentialManager,
request: GetCredentialRequest
): Result = try {
val result = credentialManager.getCredential(request = request, context = activity)
handleSignIn(result)
} catch (e: GetCredentialCancellationException) {
Result.Cancel
} catch (e: GetCredentialException) {
Result.Failure(e)
}
private fun handleSignIn(response: GetCredentialResponse): Result {
val credential = response.credential
if (credential !is CustomCredential) {
val exception =
InvalidCredentialReceivedException("Not custom credential ${credential.type}")
return Result.Failure(exception)
}
if (credential.type != GoogleIdTokenCredential.TYPE_GOOGLE_ID_TOKEN_CREDENTIAL) {
val exception =
InvalidCredentialReceivedException("Not id token credential ${credential.type}")
return Result.Failure(exception)
}
val result = getGoogleIdTokenCredential(credential)
return result
}
private fun getGoogleIdTokenCredential(credential: CustomCredential): Result = try {
val idToken = GoogleIdTokenCredential.createFrom(credential.data).idToken
Result.Success(idToken)
} catch (e: GoogleIdTokenParsingException) {
Result.Failure(e)
}
private suspend fun handleResultAndRetryIfRequired(
activity: FragmentActivity,
credentialManager: CredentialManager,
result: Result
) = when (result) {
is Result.Success,
Result.Cancel -> result
is Result.Failure -> signInWithGoogle(
activity,
credentialManager,
getCredentialOptionForButtonFlow()
)
}
companion object {
private const val WEB_CLIENT_ID = "XXXXXXXXXXXXXXX"
private fun getCredentialRequest(): GetCredentialRequest {
val googleIdOption = GetGoogleIdOption.Builder()
.associateLinkedAccounts("login", listOf("email"))
.setFilterByAuthorizedAccounts(false)
.setServerClientId(WEB_CLIENT_ID)
.build()
return GetCredentialRequest.Builder()
.addCredentialOption(googleIdOption)
.build()
}
private fun getCredentialOptionForButtonFlow(): GetCredentialRequest {
val option = GetSignInWithGoogleOption.Builder(WEB_CLIENT_ID).build()
return GetCredentialRequest.Builder()
.addCredentialOption(option)
.build()
}
}
}
sg...@google.com <sg...@google.com> #10
Not sure if this " .associateLinkedAccounts("login", listOf("email"))" is configured correctly, can you please remove this and see if this resolve your issue.
pr...@lycorp.co.jp <pr...@lycorp.co.jp> #11
What alternate way do you suggest to obtain email information ? or does it available by default without explicitly mentioning it ?.
Description
Version used: androidx.credentials:credentials:1.3.0
Devices/Android versions reproduced on: Google Pixel 7 Pro
I implemented google login with credentialManager and then button login flow as a fallback if main flow fails.
I have been reported by a user that google login is not possible on a his/her device with error message "No credentials available on this device".
I already asked user to check following things and received response mentioned against it,
1. Check google play services installed on device
> 24.47.36 (Latest while user reported)
2. Check whether device has any google account logged in
> Has one account
(Also tried to remove and add account again)
3. Check whether google signIn prompt is disabled by user through google setting
> Its turned on (enabled)
Please check how it can be resolved.