- nodejs
- postgresql
- msmtp-mta (for sending e-mails, also need to setup an smtp provider in
/etc/msmtprc
, e.g. Setup Aliyun DirectMail)
- prepare python environment
# prepare a python virtual environment first
pip install -r requirements.txt
- build front-end
For node version >= 17:
cd angular
npm i
NODE_OPTIONS=--openssl-legacy-provider npm run build
cd ..
For node version < 17:
cd angular
npm i
npm run build
cd ..
Note: the above commands only build the development package. You may replace npm run build
with npm run build-prod
to build the production (minimized) package.
- setup database
createuser auth -P
# put a new password when prompt
createdb auth -O auth
Note: You need to be a database superuser or switch to the postgres
user to run the commands above.
- download GeoLite data files
Please refer to this repo to download GeoLite2-ASN.mmdb
, GeoLite2-City.mmdb
and GeoLite2-Country.mmdb
, and save them in mmdb
folder under the project root.
- build email templates
cd mail_templates/mjml
npm i
npm run build
cd ../..
First, you may copy the example file to obtain a default configuration file.
cp config.example.json config.json
Then, please update the following settings.
- Update
SECRET_KEY
with a good random string, e.g. using the following script to generate one:
python3 -c 'import secrets; print(secrets.token_urlsafe(8))'
- Update
SQLALCHEMY_DATABASE_URI
with a postgresql db connection url,postgresql://auth:PASSWORD@127.0.0.1:5432/auth
. (replacePASSWORD
with real password) - Delete
EXTERNAL_USER_INFO
,EXTERNAL_AUTH_PROVIDERS
- Update
ADMIN
with real username, email address and password for admin. - Delete
mail_catcher
inMAIL
, edit other fields according to real setup - Edit
SITE
according to real setup
Update the variables (except production
) in the following environment files.
- angular/src/environments/environment.ts (for debugging)
- angular/src/environments/environment.prod.ts (for production)
Note: After any update, you must re-build the front-end to apply the changes.
The titles of the webpages are updated according to the environment variables mentioned above, but this update is done at runtime, requiring running the Javascript.
For SEO purpose, you need to ensure the static HTML title is also the correct one. To achieve this, please update the <title>
tag in angular/src/index.html.
Note: After any update, you must re-build the front-end to apply the changes.
Replace the following image/icon files according to your need.
- angular/src/assets/images/banner.png
- angular/src/assets/images/logo-64.png
- angular/src/assets/images/logo-128.png
- angular/src/assets/images/logo-256.png
- angular/src/favicon.ico
Note: After any update, you must re-build the front-end to apply the changes.
Update the contents of the following files according to your need.
- mail_templates/confirm_email.txt
- mail_templates/mjml/src/confirm_email.mjml
- mail_templates/mjml/src/include/header.mjml
- mail_templates/mjml/src/include/footer.mjml
Note: After any update, you must re-build the email templates and restart the server to apply the changes.
flask create-db
flask init-db
flask run -p 8077
- use a better server than flask, e.g.
gunicorn
pip install gunicorn
gunicorn -w 4 -b 127.0.0.1:8077 app:app
- use a reverse proxy (e.g. nginx) and HTTPS certificate (e.g. certbot) for public endpoint
- register system service to auto-start the server after each system reboot, e.g.
(option 1) add a systemd configuration file in /etc/systemd/system/
, e.g. idm.service
:
[Unit]
Description=idm system daemon
After=syslog.target network.target
Wants=network.target
[Service]
Type=simple
ExecStart=/home/kelvin/miniconda3/envs/idm/bin/gunicorn -w 4 -b '127.0.0.1:8077' app:app
WorkingDirectory=/home/kelvin/projects/auth
Restart=always
RestartSec=1min
[Install]
WantedBy=multi-user.target
Then, start and enable the service:
sudo systemctl start idm.service
sudo systemctl enable idm.service
(option 2) install supervisor
and add a configuration in /etc/supervisor/conf.d
, e.g. idm.conf
:
[program:idm]
user=kelvin
command=/home/kelvin/miniconda3/envs/idm/bin/gunicorn -w 4 -b '127.0.0.1:8077' app:app
directory=/home/kelvin/projects/idm
autostart=true
autorestart=true
Then, enable the service with supervisor controller:
sudo supervisorctl update