Skip to content

Latest commit

 

History

History
61 lines (43 loc) · 1.63 KB

README.md

File metadata and controls

61 lines (43 loc) · 1.63 KB
title keywords description
JWT
jwt
json web token
authentication
Using JSON Web Tokens (JWT) for authentication.

Fiber with JWT

Github StackBlitz

This example demonstrates how to use JSON Web Tokens (JWT) for authentication in a Fiber application.

Prerequisites

  • Go 1.16 or higher
  • Go modules

Setup

  1. Clone the repository:

    git clone https://github.com/gofiber/recipes.git
    cd recipes/jwt
  2. Install dependencies:

    go mod tidy

Running the Application

  1. Run the application:

    go run main.go
  2. The server will start on http://localhost:3000.

Endpoints

Method URL Description
POST /login Authenticates a user and returns a JWT
GET /restricted Accesses a restricted route with JWT

Example Requests

Login

curl -X POST http://localhost:3000/login -d '{"username": "user", "password": "pass"}' -H "Content-Type: application/json"

Access Restricted Route

curl -X GET http://localhost:3000/restricted -H "Authorization: Bearer <your_jwt_token>"

Postman Collection

You can find Postman examples here.