8legd
84339d76a2
|
8 years ago | |
---|---|---|
.. | ||
functions | 8 years ago | |
public | 8 years ago | |
README.md | 8 years ago | |
database.rules.json | 8 years ago | |
firebase.json | 8 years ago | |
main.css | 8 years ago |
README.md
Username/password sign in with Firebase
This sample shows how to authenticate with a username/password Sign-In on Firebase. In this sample we use a basic authentication request with the supplied credentials and if succesful create a Firebase Custom Token.
NOTE: Firebase Authentication can be used for email address/password sign in. This sample specifically addresses the case in which an email address is not used as the unique identifier for a user.
Setup the sample
Create and setup the Firebase project:
- Create a Firebase project using the Firebase Developer Console.
- Enable Billing on your Firebase the project by switching to the Blaze plan, this is currently needed to be able to perform HTTP requests to external services from a Cloud Function.
- Copy the Web initialisation snippet from Firebase Console > Overview > Add Firebase to your web app and paste it in
public/index.html
in lieu of the placeholder (where theTODO(DEVELOPER)
is located).
Create and provide a Service Account's credentials:
- Create a Service Accounts file as described in the Server SDK setup instructions.
- Save the Service Account credential file as
./functions/service-account.json
Deploy your project:
- Run
firebase use --add
and choose your Firebase project. This will configure the Firebase CLI to use the correct project locally. - Run
firebase deploy
to effectively deploy the sample. The first time the Functions are deployed the process can take several minutes.
Run the sample
Open the sample's website by using firebase open hosting:site
or directly accessing https://<project-id>.firebaseapp.com/
.
Enter credentials and click on the Sign in button. At this point you are authenticated in Firebase and can use the database/hosting etc...
Workflow and design
When clicking the Sign in button the auth
Function authenticates the username/password then Mints and returns a Firebase Custom Auth token (which is why we need Service Accounts Credentials).
The httpbin request & response service is used for the basic authentication request.
The main page will detect the sign-in through the Firebase Auth State observer and display the signed-In user information.