Get credentials for user auth in firebase to bind user provider

In my firebase application, users can login using

I want to give the user the ability to link both accounts. So, the case that I open is:

  • User subscribes with Google
  • The user goes to the settings and clicks "Connect with Slack".
  • The user account must be linked so that he can log in using Slack or Google the next time.

According to the documentation for linking accounts, you can call either linkWithPopup/Redirect for federated providers or auth.currentuser.link(credential) for your email provider ( https://firebase.google.com/docs/auth/web/account -linking ).

Now I'm wondering if I can somehow get AuthCredential from my custom Slack authentication and use the above link(credential) method?
Has anyone managed to successfully associate accounts with custom authorization providers?

+5
source share
1 answer

This is not supported out of the box. What you can do is the following (setting the order is required, basically switching the order):

  • Log in using user auth using slack: (the uid used here in the user auth account may be the same as the slack user ID).
  • linkWithPopup / Redirect / Credential using a Google provider or credentials for an existing slack user user.

If you insist on the proposed thread, you can do the following:

  • Log in to Google first (uid highlighted).
  • Log in using Slack (weak OAuth credentials obtained).
  • Tick ​​the Firebase ID token and skip the credentials on your server.
  • Check the Firebase identifier token, the endpoint of the slack userinfo request, to get weak user data, including the slack identifier.
  • Save the hash map with Slack ID as the key, and Firebase uid as the value, another hash map with firebase uid as the key and weak identifier as the value.
  • Configure your own token using firebase uid, set the slack custom attribute (slack: {Slack Identifier}).
  • Sending a custom token to the front end and signInWithCustomToken (the id of the slice will now be available in the token)
  • The account is now linked to an existing account.

The next time the user logs in with Slack:

  • Send weak OAuth credentials to the server.
  • Request a userinfo slice to get a weak identifier.
  • Check the hash map using the hidden identification key for the corresponding firebase uid.
  • Mint custom token with uid firebase, add a weak identifier as a custom attribute.
  • log in with a custom token on the client.

If the user logs in with Google.

  • Send the firebase identifier token to the server.
  • Check the identifier token, find the corresponding snap identifier in the hash map using the uid firebase keys.
  • Mint custom token with Firebase uid and weak identifier as a custom attribute.
  • log in with a custom token on the client.
+4
source

Source: https://habr.com/ru/post/1262018/


All Articles