Link Anonymous Benutzer mit Apple Provider mitAndroid

Forum für diejenigen, die für Android programmieren
Anonymous
 Link Anonymous Benutzer mit Apple Provider mit

Post by Anonymous »

Mit meiner Android -App können Benutzer anonym mit Firebase Auth. Später können sie bei den Einstellungen ihr Konto mit E -Mail/Kennwort erstellen/mit einem tatsächlichen Konto verknüpfen und sich anmelden. Ich möchte jetzt Apple -Anmeldung hinzufügen. Hat jemand die Schritte dafür herausgefunden? Ich habe Dokumentation, meine Umleitungs -URLs, Service -ID, Tasten korrekt und ich kann keine Lösung finden. />

Code: Select all

private val appleSignInLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
if (result.resultCode == Activity.RESULT_OK) {
result.data?.let { data ->
val response = AuthorizationResponse.fromIntent(data)
val idToken = response?.idToken.orEmpty()
val credential = OAuthProvider.newCredentialBuilder("apple.com")
.setIdTokenWithRawNonce(idToken, originalRawNonce)
.build()
lifecycleScope.launch {
try {
firebaseAuth.currentUser?.linkWithCredential(credential)?.await()?.let { result ->
updateUser(result.user?.email.orEmpty())
}
} catch (e: Exception) {
e.printStackTrace()
}
}
} ?: run {
println("---> received no data")
}
}
}

private fun linkUserToApple() {
viewModel.loading()
try {
val rawNonce = generateNonce()
val hashedNonce = sha256(rawNonce)
originalRawNonce = rawNonce
// Build Apple auth URI
val serviceConfig = AuthorizationServiceConfiguration(
Uri.parse("https://appleid.apple.com/auth/authorize"),
Uri.parse("https://appleid.apple.com/auth/token")
)
val authRequest = AuthorizationRequest.Builder(
serviceConfig,
"client-id",
ResponseTypeValues.CODE,
Uri.parse("redirect-url")
).setScopes(listOf("name", "email"))
.setResponseMode("form_post")
.setResponseType("code id_token")
.setNonce(hashedNonce)
.build()
val authService = AuthorizationService(this@ActivitySignup)
val authIntent = authService.getAuthorizationRequestIntent(authRequest)
appleSignInLauncher.launch(authIntent) // Launching intent
} catch (e: Exception) {
e.printStackTrace()
}
}

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post