Motivation
Currently, signInWithNonce always triggers the Android Credential Manager account picker UI. For features like auto-login on startup or seamless session recovery after a 401 error, we need a way to attempt sign-in without interrupting the user.
If the user has already authorized a single account, Credential Manager can resolve this silently. If no account is authorized or multiple are available, a "silent" request should fail immediately with a signal, allowing the app to decide whether to show the full UI or fall back to an anonymous/logged-out state.
Proposed API
Kotlin (GodotGoogleSignIn.kt): Add two new public methods (and a supporting internal one) to handle silent requests:
@UsedByGodot fun silentSignIn()
@UsedByGodot fun silentSignInWithNonce(rawNonce: String)
GDScript (google_sign_in.gd): Add corresponding wrappers:
func silent_sign_in()
func silent_sign_in_with_nonce(nonce: String)
Implementation notes
To achieve the "silent" behavior with the modern Credential Manager, the GetGoogleIdOption must be configured with both setAutoSelectEnabled(true) and setFilterByAuthorizedAccounts(true).
Since getCredential normally falls back to an account picker if auto-select fails, a "silent" method should explicitly detect if interaction is required and abort.
private fun signInInternal(rawNonce: String?, silent: Boolean = false) {
coroutineScope.launch {
try {
val googleIdOption = GetGoogleIdOption.Builder()
.setFilterByAuthorizedAccounts(true)
.setAutoSelectEnabled(true)
// ... (webClientId, nonce hashing)
.build()
val request = GetCredentialRequest.Builder()
.addCredentialOption(googleIdOption)
.build()
// If silent=true, we ideally want to know if UI will be shown.
// Note: Credential Manager doesn't have a check-only mode,
// but setAutoSelectEnabled(true) is the designed path for this.
val result = credentialManager.getCredential(activity, request)
handleSignInResult(result)
} catch (e: GetCredentialException) {
if (silent) {
emitSignal("google_silent_sign_in_failed", e.message)
} else {
emitSignal("google_sign_in_failed", e.message)
}
}
}
}
Motivation
Currently,
signInWithNoncealways triggers the Android Credential Manager account picker UI. For features like auto-login on startup or seamless session recovery after a 401 error, we need a way to attempt sign-in without interrupting the user.If the user has already authorized a single account, Credential Manager can resolve this silently. If no account is authorized or multiple are available, a "silent" request should fail immediately with a signal, allowing the app to decide whether to show the full UI or fall back to an anonymous/logged-out state.
Proposed API
Kotlin (
GodotGoogleSignIn.kt): Add two new public methods (and a supporting internal one) to handle silent requests:@UsedByGodot fun silentSignIn()@UsedByGodot fun silentSignInWithNonce(rawNonce: String)GDScript (
google_sign_in.gd): Add corresponding wrappers:func silent_sign_in()func silent_sign_in_with_nonce(nonce: String)Implementation notes
To achieve the "silent" behavior with the modern Credential Manager, the
GetGoogleIdOptionmust be configured with bothsetAutoSelectEnabled(true)andsetFilterByAuthorizedAccounts(true).Since
getCredentialnormally falls back to an account picker if auto-select fails, a "silent" method should explicitly detect if interaction is required and abort.