Code Monkey home page Code Monkey logo

jwt-middleware-app-hono's Introduction

JWT Middleware App (Hono)

This repository contains a simple web application built with Bun, a web framework in Go, that demonstrates how to implement JWT (JSON Web Tokens) based authentication middleware.

Introduction

JWT (JSON Web Tokens) is a compact, URL-safe means of representing claims to be transferred between two parties. The claims in a JWT are encoded as a JSON object that is used as the payload of a JSON Web Signature (JWS) structure or as the plaintext of a JSON Web Encryption (JWE) structure, enabling the claims to be digitally signed or integrity protected with a Message Authentication Code (MAC) and/or encrypted.

This repository showcases the implementation of JWT-based authentication middleware in a Bun web application.

Features

  • JWT Authentication Middleware: Implementation of JWT-based authentication middleware.
  • User Authentication: Demonstrates how to authenticate users using JWT tokens.
  • Protected Routes: Certain routes are protected and can only be accessed with a valid JWT token.
  • Token Generation: Provides functionality to generate JWT tokens for authenticated users.
  • Custom Claims: Ability to add custom claims to JWT tokens.

Usage

To use this application:

  1. Clone the repository:

    git clone https://github.com/JaphetRugas/jwt-middleware-app-hono.git
    
  2. Navigate to the project directory:

    cd jwt-middleware-app-hono
    
  3. Install dependencies:

    bun install
    
  4. Run the application:

    bun run dev
    
  5. Access the application in your web browser at http://localhost:3000.

Authentication Flow

  1. Login:

    • Make a POST request to /login endpoint with user credentials in the request body.
    • Upon successful authentication, the server responds with a JWT token.
  2. Access Dashboard:

    • Make requests to protected routes (e.g., /dashboard) with the generated JWT token.
    • Ensure the JWT token is included in the request header with the Authorization field.
    • Set the header prefix as Bearer.
    • The JWT token should be included in the header as follows:
      • Type: JWT Header
      • Algorithm: HS256
      • Secret: [Your Secret Key]
      • Request header prefix: Bearer
      • JWT header: token

Contributing

Contributions are welcome! Feel free to open an issue or submit a pull request for any improvements or features you'd like to add.

jwt-middleware-app-hono's People

Contributors

japhetrugas avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.