cjmling / findings

Notes on stuff i finds worth keeping for quick reference later on.
2 stars 0 forks source link

Firebase authentication basics theory #46

Open cjmling opened 6 years ago

cjmling commented 6 years ago

We don't authenticate user using username/password from "server/backend" side like we used to do normally. https://firebase.google.com/docs/auth/web/start

We do login in client side using firebase client library/module import firebase from 'firebase/app'; import 'firebase/auth'; and firebase client key. This client key we get from firebase console in authentication menu. (Its not same as service account key)

Before able to login in client side we have to create user with firebase auth first which is by calling this method firebase.auth().createUserWithEmailAndPassword(email, password)

Once user is created, we will see this user in authentication menu in firebase console.

Now we can login the user firebase.auth().signInWithEmailAndPassword(email, password). With this you will get user info as return value. The user info will contain email , uid and access token.

We send this access token to server.

In the server side , we use firebase admin library/module and service account credentials (need to download from google) to verify this access token with firebase. If it is correct then it will return user info which will have email, uid etc. informatin. Now we know that which user it is and proceed further.

NOTE:

  1. There is two different module , client side and server side (aka admin sdk)
  2. There is two different set of credentials , client have its own , for servicer side have it own

SEO : firebase authentication auth

cjmling commented 3 years ago

https://github.com/cjmling/findings/issues/310