@enkeldigital/firebase-authentication
Plugin to use with this library to integrate with firebase authentication.
Installation
npm install @enkeldigital/firebase-authentication
# Depends on this too
npm install create-express-auth-middleware
Example
-
Make a API call from client using this example to include an Authorization header
Authorization: Bearer <your-client-token>
-
If an API call is made with a valid token, you can access the decoded token object from request
const app = require("express")();
const { create_authn_middleware, create_authz_middleware } = require("create-express-auth-middleware");
const firebaseAuthentication = require("@enkeldigital/firebase-authentication");
const { auth } = require("@enkeldigital/firebase-admin");
app.use(create_authn_middleware(firebaseAuthentication(auth)));
app.get(
"/data/:userID",
create_authz_middleware((req) => req.jwt.userID === req.params.userID),
(req, res) => res.status(200).json({ data: "Protected user data" })
);
-
If authentication failed, you get a 401 code with the following response by default
{ "ok": false, "error": "Authentication Failed" }
-
If authorization failed, you get a 403 code with the following response by default
{ "ok": false, "error": "Authorization Failed" }
License and Author
This project is made available under MIT LICENSE and written by JJ