exposed-ktor-jwt icon indicating copy to clipboard operation
exposed-ktor-jwt copied to clipboard

example of an exposed+ktor+jwt secured kotlin app sporting an angular frontend

  • exposed-ktor-jwt
  • postgresql database running in docker for the local dev environment with configurable sql schema.
  • kotlin backend using: Jetbrains' Exposed and Ktor. Kluent and Junit5 for tests.
  • backend secured with jwt tokens. It both creates and validates the tokens on selected routes.
  • frontend: angular 7 + angular material
  • Build ** backend

#+BEGIN_SRC shell $ cd backend && gradle build #+END_SRC

** frontend

#+BEGIN_SRC sh $ cd frontend && yarn && yarn build #+END_SRC

  • Execute ** when using an IDE for kotlin (e.g. jetbrains' Intellij)
    • boot the database with =make db= in the root dir
    • execute the main function (in main.kt)
    • =cd frontend && yarn start=
    • check [[http://localhost:4200][localhost:4200]] ** running the whole project in docker
    • build the backend: =cd backend && gradle build=
    • build the frontend: =cd frontend && yarn && yarn build=
    • go to the root dir and issue: =make=
    • =note=: you must have =docker= and =docker-compose= installed
    • check [[http://localhost:4200][localhost:4200]]
  • Test the endpoints ** testing the =/secret= endpoint with postman
    • see [[https://stackoverflow.com/a/24710676/4921402][this]] so question
    • basically you have to issue a GET request containing a header row like this:

#+BEGIN_SRC text Key: 'Authorization' Value: Bearer 'yourjwttokenASDFASDFdsfasdfDSAFasdfADfADfASdafAsdFASDF' #+END_SRC

** testing the =/secret= endpoint with curl *** step 01: obtain and stash the token throught the /login endpoint #+BEGIN_SRC sh $ TOKEN=$(curl -s -X POST -d '{"name" : "alice", "password": "secret"}' -H "Content-Type: application/json" localhost:8080/login | jq -r '.token') #+END_SRC *** step 02 issue a GET /secret with a header containing the token #+BEGIN_SRC sh $ curl -H 'Accept: application/json' -H "Authorization: Bearer ${TOKEN}" https://localhost:8080/secret #+END_SRC

  • LICENSE
  • [[https://www.gnu.org/licenses/gpl-3.0.en.html][GNU General Public License v3]] #+BEGIN_SRC text GNU General Public License v3 Copyright (c) 2019-2021 Filipe Silva (ninrod) #+END_SRC