odashi / firebase-auth-minimal

Firebase Authentication/Google Identity Platform minimal example app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Firebase Auth Minimal App

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.

Getting Started

Prerequisites

You need to install Docker or a container runtime compatible with Docker before trying the steps below.

Prepare Identity Platform

  1. Prepare a Google Cloud project.
  2. Enable Identity Platform from the marketplace.
  3. Add an Email provider.

Set up the backend

  1. Open backend/main.py and replace audience config with the value corresponding to your project.
  2. Open a shell.
  3. On backend/, run docker build -t backend .
  4. Run docker run -it --rm -p 8081:8081 backend

Set up the frontend

  1. Open frontend/static/main.js and replace apiKey and authDomain configs with the values corresponding to your project.
  2. Open another shell.
  3. On frontend/, run docker build -t frontend .
  4. Run docker run -it --rm -p 8080:8080 frontend

Check how the app works

  1. Open http://localhost:8080/ on your browser.
  2. 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.
  3. 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.

About

Firebase Authentication/Google Identity Platform minimal example app

License:MIT License


Languages

Language:JavaScript 36.8%Language:Python 30.3%Language:HTML 24.1%Language:Dockerfile 8.8%