/exposed-ktor-jwt

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

Primary LanguageTypeScriptOtherNOASSERTION

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

$ cd backend && gradle build

frontend

$ cd frontend && yarn && yarn build

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 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 localhost:4200

Test the endpoints

testing the /secret endpoint with postman

  • see this so question
  • basically you have to issue a GET request containing a header row like this:
Key: 'Authorization'
Value: Bearer 'yourjwttokenASDFASDFdsfasdfDSAFasdfADfADfASdafAsdFASDF'

testing the /secret endpoint with curl

step 01: obtain and stash the token throught the /login endpoint

$ TOKEN=$(curl -s -X POST -d '{"name" : "alice", "password": "secret"}' -H "Content-Type: application/json"  localhost:8080/login | jq -r '.token')

step 02 issue a GET /secret with a header containing the token

$ curl -H 'Accept: application/json' -H "Authorization: Bearer ${TOKEN}" https://localhost:8080/secret

LICENSE

GNU General Public License v3
Copyright (c) 2019-2021 Filipe Silva (ninrod)