Skip to content

Expressjs Middleware for firebase authentication and app check when you don't want to install firebase admin sdk

License

Notifications You must be signed in to change notification settings

chientrm/firebase-verifier

Repository files navigation

firebase-verifier middleware for expressjs

ci Commit Languages Discord Dependencies Repo size Download Sponsors Issues License Version Contributors Contributors

When you don't want to install firebase-admin-sdk just to verify id token and/or app check token.

Install

npm install firebase-verifier

Configs

Obtains project_id and project_no from Google Cloud Console

Usage

import express from "express";
import {
  authVerifier,
  appCheckVerifier,
  firebaseVerifier,
} from "firebase-verifier";

const project_id = "<project_id>";
const project_no = "<project_no>";

const app = express();

// Verify Id token
app.use(authVerifier(project_id));
app.get("/", (req, res) => {
  console.log(res.locals.user);
  /* Output
    {
      "sub": "kxljssoieeJKLe",
      "email": "chientrm@gmail.com",
      ...
    }
  */
});

...

// Verify App Check token
app.use(appCheckVerifier(project_no));
app.get("/", (req, res) => {
  console.log(res.locals.device);
  /* Output
    {
      ...
    }
  */
});

...

// Verify both Id token and App Check token
app.use(firebaseVerifier({ project_id, project_no }));
app.get("/", (req, res) => {
  console.log(res.locals.user);
  console.log(res.locals.device);
});

app.listen(3000);

Check verification

If any of the verifiers failed, res.locals.user, res.locals.device are null and res.locals.error contains the error.

About

Expressjs Middleware for firebase authentication and app check when you don't want to install firebase admin sdk

Topics

Resources

License

Stars

Watchers

Forks