This example contains a minimal example Web application working with Firebase Authentication and/or Google Identity Platform.
The app consists of following servers:
- Frontend (
localhost:8080
): written in Javascript/JQuery/Firebase. - Backend (
localhost:8081
): written in Python/FastAPI/google-auth.
This example uses HTTP (not HTTPS) for frontend-backend communication for simplicity. This is in generall dangerous because the tokens are exchanged without any encryption. Do not release the bare HTTP backend in your real production systems if it need to exchange any private information.
You need to install Docker or a container runtime compatible with Docker before trying the steps below.
- Prepare a Google Cloud project.
- Enable Identity Platform from the marketplace.
- Add an Email provider.
- Open
backend/main.py
and replaceaudience
config with the value corresponding to your project. - Open a shell.
- On
backend/
, rundocker build -t backend .
- Run
docker run -it --rm -p 8081:8081 backend
- Open
frontend/static/main.js
and replaceapiKey
andauthDomain
configs with the values corresponding to your project. - Open another shell.
- On
frontend/
, rundocker build -t frontend .
- Run
docker run -it --rm -p 8080:8080 frontend
- Open
http://localhost:8080/
on your browser. - You may be requested to log into the service with an E-mail address. If your Identity Platform enabled the "Enable create (sign-up)" option, the sign-in form also works to sign-up a new user.
- After logging into the service, you may see two buttons: "Fetch backend" and "Sign out". "Fetch backend" invokes the backend server with the obtained ID token, and returns a user-specific data: the name of the user.