reitit/examples/buddy-auth
2025-10-24 15:52:47 +03:00
..
src/example Add Buddy example 2020-07-11 13:35:43 +03:00
.gitignore Add Buddy example 2020-07-11 13:35:43 +03:00
project.clj Release 0.9.2-rc1 2025-10-24 15:52:47 +03:00
README.md examples/buddy-auth: README improvements and dep upgrade 2020-07-24 13:51:10 +03:00

Buddy auth example

A sample project that shows how to use Buddy authentication with Reitit to implement simple authentication and authorization flows.

  • Basic auth
  • Token-based authorization with JWT tokens

Usage

Start a REPL:

lein repl

Start the server:

(start)

Take a look at the annotated example in server.clj.

You can also try some curl commands:

# Let's first try without password - this should fail
curl http://localhost:3000/basic-auth

# With password, it should work
curl http://user1:kissa13@localhost:3000/basic-auth

# The response should look something like this:
#
#    {"message":"Basic auth succeeded!","user":{"id":1,"roles":["admin","user"],
#     "token":"eyJhbGciOiJIUzUxMiJ9.eyJpZCI6MSwicm9sZXMiOlsiYWRtaW4iLCJ1c2VyIl0sImV4cCI6MTU5NTU5NDcxNn0.lPFcLxWMFK4_dCLZs2crPB2rmvwO6f-uRsRYdhaWTAJHGKIQpP8anjbmnz6QlrS_RlI160FVzZohPlmkS9JfIQ"}}
#
# The value in the JSON field `token` is a JWT token. A new one is generated with every call and they expire in two hours.

# We can try token auth then. Copy the token from the response in the next command:
curl -H "Authorization: Token PASTE_YOUR_TOKEN_HERE" http://localhost:3000/token-auth

License

Copyright © Metosin Oy and collaborators.