Reputation: 1321
I am building a Flutter app that does a auth.SignInWithCredential({'accessToken'...,'idToken'...})
I want the application to do backend request, sending a Bearer token. On the backend I need to authenticate this user using firebase AND use the oAuth2 token for Google-services, because it is scoped.
I have no smart idea to do this (besides sending 2 tokens in the request headers, which seems to be overkill).
Upvotes: 1
Views: 755
Reputation: 1321
My final solution is to only send the Google-token to the backend, and use the signInWithIdp to generate a Firebase ID token. This works on any server.
const response = await fetch('https://identitytoolkit.googleapis.com/v1/accounts:signInWithIdp?key=[firebase_web_key]',
{ 'method': 'POST',
body: JSON.stringify({
postBody: "access_token="+req.token+"&providerId=google.com",
requestUri: "https://[firebase-project].firebaseapp.com",
returnIdpCredential: true,
returnSecureToken: true,
}) })
// contains idToken!
const idpData = await response.json()
res.locals.decodedIdToken = await admin.auth().verifyIdToken(idpData.idToken);
```
Upvotes: 2