Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set identifier on firebase authentication via custom token?

I just implemented the linkedin signup & login using firebase custom auth system through this https://firebase.google.com/docs/auth/admin/create-custom-tokens

Identifier is -

It`s working but identifier on firebase is null.

How should I send it? Should I update it after creating the user? I want to save it on create.

Thanks

like image 336
Mete Kabak Avatar asked Jul 09 '18 18:07

Mete Kabak


People also ask

How do I verify my Firebase custom token?

To do so securely, after a successful sign-in, send the user's ID token to your server using HTTPS. Then, on the server, verify the integrity and authenticity of the ID token and retrieve the uid from it. You can use the uid transmitted in this way to securely identify the currently signed-in user on your server.

How can I add my name in Firebase authentication?

You create a new user in your Firebase project by calling the createUserWithEmailAndPassword method or by signing in a user for the first time using a federated identity provider, such as Google Sign-In or Facebook Login.

What is custom token authentication?

What Are Custom Authentication Tokens? An authentication token is some data, represented as a string or XML, that identifies an entity (user or process), such as an X509 client certificate. Typically, authentication tokens are designed to be used within specific security protocols.


1 Answers

Try this: On your server, before minting the custom token, you can create the user with the email:

// Create the user with email first.
admin.auth().createUser({uid: uid, email: linkedinEmail})
  .then(function(userRecord) {
    // This will return custom token for that user above.
    return admin.auth().createCustomToken(userRecord.uid);
  })
  .catch(function(error) {
    // Some error.
  });

Another option using client side code, is to set the email client side after signing in with custom token:

firebase.auth().signInWithCustomToken(customToken)
  .then(function(result) {
    return firebase.auth().currentUser.updateEmail(linkedinEmail);
  })
  .catch(function(error) {
    // Some error occurred.
  });
like image 161
bojeil Avatar answered Oct 16 '22 10:10

bojeil