The name is open for discussion.
-
Make sure you have a recent version of rust installed.
-
We currently use a postgresql server for persistent storage (also in development mode). So you'll have to install and run your own postgresql server. After installation, you can start a postgresql shell with
psql, but you will likely need access it as the postgres user, so use e.g.sudo -u postgres psql. -
Next, in this shell, you'll have to create a user with permissions to create a database:
CREATE USER zauth WITH PASSWORD 'zauth' CREATEDB;
Note that by default the postgresql server is configured to not allow for username:password authentication. Please refer to the official documentation for information about postgresql authentication.
Execute
SHOW hba_file;in the psql shell to find the location of the client authentication file, which might for example be/var/lib/pgsql/data/pg_hba.conf.A configuration allowing password authentication for the zauth user on the local system could look like this:
host all zauth 127.0.0.1/32 md5 host all zauth ::1/128 md5 -
We use diesel to manage our database. Install the cli with
cargo install diesel_cli. If you wish to only install the postgres features ofdiesel(for nix-shell for example), runcargo install diesel_cli --no-default-features --features postgres --force
-
Create the development and testing database with
diesel database reset --database-url "postgresql://zauth:zauth@localhost/zauth" diesel database reset --database-url "postgresql://zauth:zauth@localhost/zauth_test"
This will also run the migrations.
-
Run
npm installto install all the node dependencies. -
Run
npm run buildto compile the css assets.
When working on the stylesheets, you can runnpm run watchto automatically recompile them on every change. -
If you want to receive mails in development you can start the mail server with
docker compose up maildev -dand view your mails in the browser athttp://localhost:8000.
Don't forget to set the following config variables in the config file:
mail_server = "localhost"
mail_port = 1025
mail_password = "mailpass"
mail_username = "mail"-
You can now start the server with
cargo run. If you want to create an admin user you can start it with theZAUTH_ADMIN_PASSWORDenvironment variable:ZAUTH_ADMIN_PASSWORD=adminadmin cargo run
The server should then run on localhost:8000 and create an admin user with password 'adminadmin'.
There are also other environment variables like:
ZAUTH_EMPTY_DB=trueto clean the database from users and clientsZAUTH_CLIENT_NAME=mozaic_incto create a client with the name mozaic_incZAUTH_SEED_USER=100to create 100 users, some are active, some are pending (always creates the same users)ZAUTH_SEED_CLIENT=100to create 100 clients, some need a grant, others don't (always creates the same clients)
You can now start developing! A good way to start is to look at the routes defined in the controllers.
There are tests trying out the OAuth2 flow which can be run with cargo test.
You can also test the OAuth2 flow manually by running the flask application in
test_client/client.py.
To make a change to the database scheme, we use diesel migrations
- To create a migration, run
diesel migration generate <migration name> - Fill in the generated
up.sqlanddown.sql - Re-generate
src/models/schema.rsby runningdiesel print-schemaCaution: at the moment, the
usersschema cannot be generated correctly automatically.
We have provided a flake.nix for easy setup for Nix users. With flakes enabled, run nix develop.