Skip to content

Add [FirebaseAuth].[signInWithFirebaseidToken] to [FirebaseAuth] for [JVM] #831

Description

@mylockerbiz
Library Class Member Platforms
e.g auth e.g FirebaseAuth e.g signInWithGithub e.g Android, iOS
i am trying to use gitlive for firebase . it works fabulous for android. my app needs desktop/jvm support.
i can get a valid firebase idtoken but i cannot get a valid firebaseUser object that allows the firebase Storage security rules to be satisfied.

critical for continued usage.

here is the code in its latest iteration. Grok has lead me through multiple scenarios, all without the firebaseuser

var jsonResponse = ""
try
{
	val urlString = "https://identitytoolkit.googleapis.com/v1/accounts:signInWithIdp?key=${Secrets.gs_apikey}"
	println("desktop ✅ Google client.post to ${urlString}")
	try
	{
		jsonResponse = signInWithGoogleIdTokenRaw(urlString, idToken)
		println("desktop ✅ Response: $jsonResponse")
		// Parse 'jsonResponse' manually using a JSON library (e.g., kotlinx.serialization or org.json)
	}
	catch (e: Exception)
	{
		e.printStackTrace()
	}


	var jsonElement = Json.parseToJsonElement(jsonResponse)
	var jsonObject = jsonElement.jsonObject

	// Extract fields manually
	val localId = jsonObject["localId"]?.jsonPrimitive?.content
	val idToken = jsonObject["idToken"]?.jsonPrimitive?.content
	val refreshToken = jsonObject["refreshToken"]?.jsonPrimitive?.content
	val email = jsonObject["email"]?.jsonPrimitive?.contentOrNull
	val displayName = jsonObject["displayName"]?.jsonPrimitive?.contentOrNull
	val photoUrl = jsonObject["photoUrl"]?.jsonPrimitive?.contentOrNull
	// Handle 'emailVerified' which is a Boolean
	val emailVerified = jsonObject["emailVerified"]?.jsonPrimitive?.boolean ?: false

	println("desktop ✅ UID: $localId")
	println("desktop ✅ Token: $idToken")
	println("desktop ✅ displayName: $displayName")
	println("desktop ✅ Email Verified: $emailVerified")
	val userJson = """
{
    "uid": "$localId",
    "email": "$email",
    "idToken": "$idToken",
	"displayName:": "$displayName",
    "refreshToken": "$refreshToken",
	"photoURL": "$photoUrl",
    "providerId": "google.com",
    "isAnonymous": false,
    "creationTimestamp": ${System.currentTimeMillis()},
    "lastLoginTimestamp": ${System.currentTimeMillis()}
}

""".trimIndent()
println("desktop ✅ userJson: \n$userJson")

// Manually inject into GitLive's internal storage
// This key is specific to the JVM implementation of the SDK
PlatformOWJFirebaseInitializer.platformImpl.store(PlatformOWJFirebaseInitializer.FIREBASEUSERSTORAGEKEY, userJson)
//force a reload of the data
val stored = PlatformOWJFirebaseInitializer.platformImpl.retrieve(PlatformOWJFirebaseInitializer.FIREBASEUSERSTORAGEKEY)
println("desktop ✅ Stored content: $stored")
jsonElement = Json.parseToJsonElement(userJson)

	kotlinx.coroutines.delay(100)

// Access currentUser
var firebaseUser = Firebase.auth.currentUser

	if (firebaseUser == null) {
		println("desktop ✅ User still null. Checking storage content...")
		// Debug: Verify what was actually stored, showing a valid firebase idtoken
		val stored = PlatformOWJFirebaseInitializer.platformImpl.retrieve(PlatformOWJFirebaseInitializer.FIREBASEUSERSTORAGEKEY)
		println("desktop ✅ Stored content: $stored")
		if ( firebaseUser!=null)
		{
			OWJAuthUser.fromFirebaseUser(firebaseUser)
		}
	}


	return firebaseUser

Metadata

Metadata

Assignees

No one assigned

    Labels

    API coverageRequest for missing APIs

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions