This is a playground repo where I explore rust based on this tutorial.
It is example JWT authentication using Warp framework.
There are two users:
password | ||
---|---|---|
user | [email protected] | 1234 |
admin | [email protected] | 4321 |
curl http://localhost:8000/login -d '{"email": "", "password": ""}' -H 'Content-Type: application/json'
This will response with a token which you need to copy in order to use user endpoint
First, log in as user
To use this endpoint you need to replace
<TOKEN>
with token acquired from login endpoint
curl http://localhost:8000/user -H 'Authorization: Bearer <TOKEN>' -H 'Content-Type: application/json'
This should be the response: Hello User 1
and to this command
curl http://localhost:8000/admin -H 'Authorization: Bearer <TOKEN>' -H 'Content-Type: application/json'
This should be the response after using token from logging as user: {"message":"no permission","status":"401 Unauthorized"}
First log in as admin.
To use this endpoint you need to replace
<TOKEN>
with token acquired from login endpoint
After using admin endpoint, such as this:
curl http://localhost:8000/admin -H 'Authorization: Bearer <TOKEN>' -H 'Content-Type: application/json'
This should be the response: Hello Admin 2
After using user endpoint, such as this:
curl http://localhost:8000/user -H 'Authorization: Bearer <TOKEN>' -H 'Content-Type: application/json'
This should be the response: Hello User 2