Skip to content

Commit b50722c

Browse files
committed
KTOR Example README
1 parent 88975d0 commit b50722c

2 files changed

Lines changed: 37 additions & 0 deletions

File tree

examples/ktor-server/README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# JWT Kotlin Multiplatform - KTOR Server Example
2+
3+
This module contains a simple example for how to use the jwt-kt library for signing and verifying JWTs using an ECDSA key pair and JSON Web Keys.
4+
5+
## Run
6+
7+
Start the server:
8+
```shell
9+
.\gradlew :examples:ktor-server:jvmRun
10+
```
11+
12+
### Test
13+
14+
#### JWKS Endpoint:
15+
```shell
16+
curl -v http://localhost:8080/.well-known/jwt/jwks.json
17+
```
18+
19+
#### Login:
20+
```shell
21+
curl -v -X POST -H "Content-Type: application/json" http://localhost:8080/login -d '{"username":"username", "password":"password"}'
22+
```
23+
24+
This will return an access token.
25+
26+
#### Authenticated Route
27+
28+
Replace `<TOKEN>` with the access token from the previous step:
29+
```shell
30+
curl -H "Authorization: Bearer <TOKEN>" http://localhost:8080/hello
31+
```
32+
33+
This should return an HTTPS 200 response. During the lifetime of the token (5 minutes) and an http 401 after expiry.

examples/ktor-server/build.gradle.kts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ kotlin {
1919
mainClass.set("com.appstractive.ApplicationKt")
2020
}
2121
}
22+
23+
mainRun {
24+
mainClass.set("com.appstractive.ApplicationKt")
25+
}
2226
}
2327

2428
linuxX64().apply {

0 commit comments

Comments
 (0)