iris/_examples/auth/jwt/tutorial
Gerasimos (Makis) Maropoulos 5ef854d835
add mathx.RoundToInteger helper
2024-01-13 12:56:59 +02:00
..
api add example for https://github.com/kataras/iris/issues/1671 2020-11-13 00:34:17 +02:00
domain add a jwt tutorial + go client 2020-11-04 21:12:13 +02:00
go-client replace ioutil with io package and other minor improvements 2022-06-17 22:03:18 +03:00
util add a jwt tutorial + go client 2020-11-04 21:12:13 +02:00
go.mod add mathx.RoundToInteger helper 2024-01-13 12:56:59 +02:00
go.sum add mathx.RoundToInteger helper 2024-01-13 12:56:59 +02:00
main.go add example for https://github.com/kataras/iris/issues/1671 2020-11-13 00:34:17 +02:00
README.md OK, I think we are done with the new JWT package 2020-11-05 10:47:56 +02:00

Iris JWT Tutorial

This example show how to use JWT with domain-driven design pattern with Iris. There is also a simple Go client which describes how you can use Go to authorize a user and use the server's API.

Run the server

$ go run main.go

Authenticate, get the token

$ curl --location --request POST 'http://localhost:8080/signin' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'username=admin' \
--data-urlencode 'password=admin'

> $token

Get all TODOs for this User

$ curl --location --request GET 'http://localhost:8080/todos' \
--header 'Authorization: Bearer $token'

> $todos

Get a specific User's TODO

$ curl --location --request GET 'http://localhost:8080/todos/$id' \
--header 'Authorization: Bearer $token'

> $todo

Get all TODOs for all Users (admin role)

$ curl --location --request GET 'http://localhost:8080/admin/todos' \
--header 'Authorization: Bearer $token'

> $todos

Create a new TODO

$ curl --location --request POST 'http://localhost:8080/todos' \
--header 'Authorization: Bearer $token' \
--header 'Content-Type: application/json' \
--data-raw '{
    "title": "test titlte",
    "body": "test body"
}'

> Status Created
> $todo