Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How would I authorize users using Discord Oauth2.0 for Firebase Authentication on the Web [closed]

How would I authenticate users with Discord's OAUTH Api (https://discordapp.com/developers/docs/topics/oauth2) for Firebase?

I'm new to this sort of thing, so I would really appreciate the help!

like image 386
TransmissionsDev Avatar asked Sep 05 '25 03:09

TransmissionsDev


1 Answers

Here is my recommendation :

1.Build Firebase Cloud Function

2.Call the Firebase Cloud Function from the front end application

3.In the Cloud Function , re-direct to Discord and complete the oAuth flow

4.On completion of oAuth flow and once the Discord token is received back in the cloud function , mint a new token using Firebase Admin SDK. Add uid as one of the parameter while minting the token. This uid can be the user name or user id sent by Discord in their token response.

5.Once the Firebase token is minted, send back the token to the front end application.

6.From the app , again call the Firebase SDK to Sign-in to Firebase with SignInCustomToken sdk and send the Firebase token sent by Cloud Function

7.Above step will insert a user record in Firebase Authentication system, if not available already.

8.Use the Firebase id token and access token for all interactions with Firebase going forward.

Reference : Create Custom token using Firebase Admin SDK https://firebase.google.com/docs/auth/admin/create-custom-tokens

You can skip the step with regard to service account because the Firebase Cloud Function provides the necessary wrapper to generate custom token directly without a service account concept.

Thanks,

Dinakaran

like image 132
Dinakaran Sankaranarayan Avatar answered Sep 07 '25 20:09

Dinakaran Sankaranarayan