Search code examples
firebaseoauth-2.0firebase-authenticationgoogle-cloud-functionssalesforce

Creating firebase user with authentication information from Salesforce


I have a scenario where I am doing OAuth2 authorization to Salesforce and I get in response access token, refresh token etc. I can of course use the access token to get the user info from Salesforce.

The backend of the application is in cloud functions and these needs to be secured with authentication. I would like to secure these with the Firebase authentication information.

Is it possible to create the Firebase user with the OAuth2 authorization information from Salesforce programatically without having to ask the user to authenticate separately to Firebase


Solution

  • One way to implement this use-case is with custom authentication in Firebase. Step-by-step you:

    1. Sign the user in to Salesforce as you already do
    2. Take the relevant information from their Salesforce token
    3. Mint a Firebase token with that information (this happens in a trusted environment)
    4. Sign the user in to Firebase with the token (this happens on the client).

    The Firebase specific steps 3 and 4 can be done without user interaction.

    You can then use the information of the user that is signed in to Firebase in the usual way.