I am working on a web app that has "Sign in with Google" and "Login with Facebook" buttons. After user successfully signs into the app backed by Firebase, I want to be able to make API calls to their Google and Facebook data. Example is fetch their photos from Google Photos or Facebook.
Normally this is easy to do when you use Google Auth APIs on web and on signing in, you get Auth Code that you can pass to your server and server exchanges that one-time-use code for Access Token and Refresh Token and store them on server side for any future API calls. Here is a link to tutorial for this approach - https://developers.google.com/identity/sign-in/web/server-side-flow
With Firebase being my backend and with FirebaseUI authenticating users to my web app, how can I get the code that I can pass to Firebase Function which can then exchange it for Access Token and Refresh Token and save it into Firestore for further API calls.
You can use the signInSuccessWithAuthResult
callback from firebaseUI: https://github.com/firebase/firebaseui-web#signinsuccesswithauthresultauthresult-redirecturl
It will expose the userCredential object. For OAuth providers like google and facebook, you can access the OAuthCredetial using userCredential.credential
. The reference for this interface is here: https://firebase.google.com/docs/reference/js/firebase.auth.OAuthCredential