Home > database >  How to pass Firebase Custom Token to client?
How to pass Firebase Custom Token to client?

Time:08-18

I have a project that requires the usage of login via Facebook and Google, so I picked Firebase to speed up the process of authentication; However, the user must also be able to login via LINE(a messaging app popular in SEA).

Currently, I have implemented:

Line Login-> Finish Login -> Redirect to Cloud Functions -> Verify Line's Access_Token -> Create a User In Firebase from LINE's ID Token -> Create Custom Token from Firebase User

All that's left is to implement signInWithCustomToken and then get the idToken from firebase to send to my api for authorisation.

Now, the signIn process should be handled by the client side, but I am not sure how to pass the customToken to the client side(Our backend api and frontend client is separated).

I could pass it in a query param as I redirect the user to the frontend, but I am not sure if that's the best way to go about it.

What should I do?

CodePudding user response:

After the user has logged in to LINE, it redirects to any link you set for it to redirect to with the url params being the authorisation code and state, so ?code=xxxxxx&state=xxxxx ... I decided to use cloud function to be the redirect url for the LINE Login

If I understand correctly, instead of directly redirecting LINE to the Cloud Function, you should probably redirect to a page of your web application which, in turns, calls a Callable Cloud Function (passing the code and statevalues as arguments).

This Cloud Function verifies the token as well as creates a user in Firebase and when this is done, sends back the token to the page of your web application. You then have all the elements to call the signInWithCustomToken() method.

  • Related