diff --git a/examples/buddy-auth/README.md b/examples/buddy-auth/README.md index 51b588ed..aec465bf 100644 --- a/examples/buddy-auth/README.md +++ b/examples/buddy-auth/README.md @@ -1,16 +1,49 @@ # Buddy auth example -A Sample project with Buddy Authentication. +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 + +[Buddy]: https://github.com/funcool/buddy ## Usage +Start a REPL: + +```sh +lein repl +``` + +Start the server: + ```clj -> lein repl (start) ``` -See annotated example in [server.clj](src/example/server.clj) file. +Take a look at the annotated example in [server.clj](src/example/server.clj). + +You can also try some curl commands: + +```sh +# 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 © 2017-2018 Metosin Oy +Copyright © Metosin Oy and collaborators. diff --git a/examples/buddy-auth/project.clj b/examples/buddy-auth/project.clj index 3fdc0bd0..92dabd19 100644 --- a/examples/buddy-auth/project.clj +++ b/examples/buddy-auth/project.clj @@ -1,7 +1,7 @@ (defproject ring-example "0.1.0-SNAPSHOT" :description "Reitit Buddy Auth App" - :dependencies [[org.clojure/clojure "1.10.0"] - [ring/ring-jetty-adapter "1.7.1"] - [metosin/reitit "0.5.3"] + :dependencies [[org.clojure/clojure "1.10.1"] + [ring/ring-jetty-adapter "1.8.1"] + [metosin/reitit "0.5.5"] [buddy "2.0.0"]] :repl-options {:init-ns example.server})