https://github.com/percival33/rust-jwt-server
Rust exploration playground demonstrating JWT authentication using the Warp framework
https://github.com/percival33/rust-jwt-server
jwt rust warp
Last synced: about 1 year ago
JSON representation
Rust exploration playground demonstrating JWT authentication using the Warp framework
- Host: GitHub
- URL: https://github.com/percival33/rust-jwt-server
- Owner: Percival33
- License: mit
- Created: 2023-10-05T20:53:27.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-10-05T20:53:51.000Z (over 2 years ago)
- Last Synced: 2025-01-23T06:44:58.183Z (over 1 year ago)
- Topics: jwt, rust, warp
- Language: Rust
- Homepage:
- Size: 4.88 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# rust-jwt-server
This is a playground repo where I explore rust based on [this](https://youtu.be/6oMoHZZeyb0) tutorial.
It is example JWT authentication using Warp framework.
## Usage
There are two users:
| | email | password |
|-------|------------------|----------|
| user | user@jarcin.dev | 1234 |
| admin | admin@jarcin.dev | 4321 |
### Login
```bash
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
### User Endpoint
First, log in as user
> **To use this endpoint you need to replace `` with token acquired from login endpoint**
```bash
curl http://localhost:8000/user -H 'Authorization: Bearer ' -H 'Content-Type: application/json'
```
This should be the response: `Hello User 1`
and to this command
```bash
curl http://localhost:8000/admin -H 'Authorization: Bearer ' -H 'Content-Type: application/json'
```
This should be the response after using token from logging as user: ` {"message":"no permission","status":"401 Unauthorized"} `
### Admin Endpoint
First log in as admin.
> **To use this endpoint you need to replace `` with token acquired from login endpoint**
After using admin endpoint, such as this:
```bash
curl http://localhost:8000/admin -H 'Authorization: Bearer ' -H 'Content-Type: application/json'
```
This should be the response: `Hello Admin 2`
After using user endpoint, such as this:
```bash
curl http://localhost:8000/user -H 'Authorization: Bearer ' -H 'Content-Type: application/json'
```
This should be the response: `Hello User 2`