Я реализую вход в Google с аутентификацией Firebase на Android, используя API новой платформы идентификационной платформы. В то время как я успешно получаю имя пользователя и URL -адрес фотографии, электронная почта неизменно является нулевой.
code
Код: Выделить всё
override fun signInWithGoogle() {
viewModelScope.launch {
authManager.startLoading()
try {
authManager.clearCredentials()
val result = authManager.getGoogleCredential()
processSignInResult(result)
} catch (e: Exception) {
handleException(e)
} finally {
authManager.stopLoading()
}
}
}
private suspend fun processSignInResult(result: GetCredentialResponse) {
val credential = result.credential
if (credential is CustomCredential &&
credential.type == GoogleIdTokenCredential.TYPE_GOOGLE_ID_TOKEN_CREDENTIAL
) {
try {
val idToken = authManager.extractIdToken(credential)
val authResult = authManager.authenticateWithFirebase(idToken)
handleAuthResult(authResult)
} catch (e: Exception) {
handleException(e)
}
}
}
private suspend fun handleAuthResult(authResult: AuthResult) {
try {
val firebaseUser = authManager.getFirebaseUser(authResult)
val userId = authManager.getUserId(firebaseUser)
val userProfileMap = userProfileManager.createInitialProfile(firebaseUser, userId)
val userProfileJson = storeUserProfile(userProfileMap)
handleUserRegistrationStatus(userId, userProfileJson)
} catch (e: Exception) {
handleException(e)
}
}
private suspend fun storeUserProfile(userProfileMap: Map): String {
val userProfileJson = userProfileMapper.convertMapToJson(userProfileMap)
authManager.updateUserProfileJson(userProfileJson)
return userProfileJson
}
private suspend fun handleUserRegistrationStatus(userId: String, userProfileJson: String) {
if (remoteUserRepository.isUserRegistered(userId)) {
syncExistingUser(userId)
} else {
authStateHolder.setRequiresConsent(userId, userProfileJson)
}
}
private suspend fun syncExistingUser(userId: String) {
try {
userProfileManager.syncExistingUser(userId)
} catch (e: Exception) {
handleException(e)
}
}
Token payload: {
"iss": "https://accounts.google.com",
"name": "Yoonseol Lee",
"picture": "https://lh3.googleusercontent.com/...",
"given_name": "윤설",
"family_name": "이"
// No email field
}
Firebase User details:
- UID: [present]
- Email: null
- DisplayName: Yoonseol Lee
- PhotoUrl: [present]
- ProviderId: firebase
Provider[0]:
- ProviderId: firebase
- Email: null
- DisplayName: Yoonseol Lee
Provider[1]:
- ProviderId: google.com
- Email: null
- DisplayName: Yoonseol Lee
< /code>
что я попробовал < /strong> < /p>
Добавленная область электронной почты в экране согласия GCP OAuth
Проверка настройки аутентификации Firebase (Несколько учетных записей с той же электронной почтой отключены)
Пробусло получить доступ к электронной почте через данные по провайдеру
Проверенный SHA-1 Сертификат отпечатка пальца в Firebase Console
Reblyded и применяется новые Google-services.json < /p >
Environment < /strong> < /p>
Android Studio Hedgehog
Последняя версия Auth Auth Auths
Использование API новой платформы идентификационной платформы (не Умеренный googlesigninclient) < /p>
Вопрос < /strong>
Почему поле электронной почты NULL, несмотря на успешно получение других пользовательских данных? Как я могу правильно получить адрес электронной почты пользователя?
Любая помощь будет оценена! < /P>
Подробнее здесь: https://stackoverflow.com/questions/794 ... er-data-na