An example compojure-api application demonstrating everything you need for token based authentication using buddy.
The project pulls sensitive information from environment variables. For local
development you will need a profiles.clj
in the root of the project. Populate
the file like so:
{:dev-env-vars {:env {:database-url "postgres://auth_user:[email protected]:5432/auth?stringtype=unspecified"
:user-email "[email protected]"
:user-pass-key "mandrill-pass-key"
:auth-key "theSecretKeyUsedToCreateAndReadTokens"}}
:test-env-vars {:env {:database-url "postgres://auth_user:[email protected]:5432/auth_test?stringtype=unspecified"
:auth-key "theSecretKeyUsedToCreateAndReadTokens"}}}
CREATE DATABASE auth;
CREATE DATABASE auth_test;
\c auth;
CREATE EXTENSION citext;
c\ auth_test;
CREATE EXTENSION citext;
CREATE ROLE auth_user LOGIN;
ALTER ROLE auth_user WITH PASSWORD 'password1';
GRANT ALL PRIVILEGES ON DATABASE auth to auth_user;
GRANT ALL PRIVILEGES ON DATABASE auth_test to auth_user;
lein run -m authenticated-compojure-api.server 3000
When you start the server any needed tables will be created automatically.
Starting out you will need to create a basic
permission in the permissions
table.
INSERT INTO permission (permission)
VALUES ('basic');
You will now be able to create new users.
lein test