I am developing a Kotlin Multiplatform / Compose Multiplatform app for Android and Desktop.I want to store data on a Cloud Firestore database and on Cloud Storage.For my requests, I use Ktor.
I first started by trying to use the endpoint to create a new document :
https://firestore.googleapis.com/v1/{parent=projects/*/databases/*/documents/**}/{collectionId}
Without setting any rules on my firestore database and it worked fine.
Then I wanted to add support for authentication through email & password. When I used the signUp endpoint to sign up :
https://identitytoolkit.googleapis.com/v1/accounts:signUp?key=[API_KEY]
The idToken I got worked with the request to add a new document to Firestore. But when I used the signInWithPassword endpoint:
https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword?key=[API_KEY]
The idToken I get doesn't work with the request to create a new document, I get this error :
{"error": {"code": 401,"message": "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.","status": "UNAUTHENTICATED" }}
I use this token in the header as "Authorization" :
curl -X POST \-H "Authorization: Bearer MY_ID_TOKEN" \-H "Content-Type: application/json" \-d '{"fields": {"name": {"stringValue": "Example Name"},"age": {"integerValue": "30"} }}' \"https://firestore.googleapis.com/v1/projects/MY_PROJECT_ID/databases/(default)/documents/MY_COLLECTION_NAME"
I checked on JWT and the token seams to be valid (I have my user's info + not expired).
So now I'm lost and can't find a way to make it work. Could anyone help ? With cURL examples or using ktor, whichever you are more confortable with.