title | keywords | description | |||
---|---|---|---|---|---|
JWT |
|
Using JSON Web Tokens (JWT) for authentication. |
This example demonstrates how to use JSON Web Tokens (JWT) for authentication in a Fiber application.
- Go 1.16 or higher
- Go modules
-
Clone the repository:
git clone https://github.com/gofiber/recipes.git cd recipes/jwt
-
Install dependencies:
go mod tidy
-
Run the application:
go run main.go
-
The server will start on
http://localhost:3000
.
Method | URL | Description |
---|---|---|
POST | /login | Authenticates a user and returns a JWT |
GET | /restricted | Accesses a restricted route with JWT |
curl -X POST http://localhost:3000/login -d '{"username": "user", "password": "pass"}' -H "Content-Type: application/json"
curl -X GET http://localhost:3000/restricted -H "Authorization: Bearer <your_jwt_token>"
You can find Postman examples here.