This project is for easily implementing authentication and authorization using firebase session cookies.
It creates express server that serves as authentication middleware and reverse proxy authenticated and authorized requests to the intended application.
- Firebase account
- node and npm OR docker and docker-compose
- Configuration options can be defined by creating .env file in the root folder. Use .env.template file for reference.
Available options are specified here
- Using the .env file is optional for running directly with node. When running with docker-compose the file must exists and the value PORT must be defined there, the rest are optional
- Copy service account private key json file into config directory
- Create firebase web client config object in a json file and copy into config directory
npm run start
- Stop with ctrl+c
docker-compose up --build -d
(also supported withnpm run start:docker
)- Stop with
docker-compose down
(also supported withnpm run stop:docker
)
docker run -p [HOST PORT:CONTAINER PORT] -v ${PWD}/config:/var/www/firebase-auth-proxy/config fishondor/firebase-auth-reverse-proxy
- Set environment variables with -e flag. Ex:
docker run -p 80:80 -v ${PWD}/config:/var/www/firebase-auth-proxy/config -e "AUTHORIZED_EMAIL_DOMAIN=[VAR VALUE]" -e "COOKIE_NAME=[VAR VALUE]" fishondor/firebase-auth-reverse-proxy
Name | Description | Default value |
---|---|---|
PORT | Port the server will listen on | 80 |
REVERSE_PROXY_TARGET_PORT | Port of the service that requests will be forwarded to (in localhost) | 8080 |
SERVICE_ACCONT_FILE_NAME | Name of the service account private key file | service-account.json |
FIREBASE_CONFIG_FILE_NAME | Name of the json file created with web client firebase configuration | firebase-config.json |
COOKIE_DOMAIN | Domain for registering session cookie (default null will set it to current domain) Read more | null |
COOKIE_MAX_AGE | Expiration time for session cookie in miliseconds Read more | 86400000 |
COOKIE_NAME | Name of session cookie Read more | __reverse_proxy_session |
AUTHORIZED_EMAIL_DOMAIN | Domain to use for authorizing user by email (some_user@domin.com). Default value of false means authorizing everybody | false |
SAVE_COOKIE_ENDPOINT | The name of the route for creating and saving session cookie | savecookie |
Inspired by these resources: