Giter VIP home page Giter VIP logo

go-json-web-token-example's Introduction

JWT Authentication API in Go

This is a simple JWT authentication API written in Go. It allows users to sign up, sign in, and view their user profile by providing a JWT token in the request headers.

Features

  • User sign-up: Users can register by providing an email and password.
  • User sign-in: Users can authenticate by providing their registered email and password, and receive a JWT token.
  • User profile: Authenticated users can view their user profile by providing the JWT token in the request headers.

Installation

  1. Clone this repository:

  2. Navigate to the project directory:

  3. Install dependencies:

    go mod tidy
  4. Build and run the server:

    go run jwtExample.go

    The server will start running at http://localhost:8080.

Endpoints

  • POST /signup: Register a new user.

    • Request Body: JSON object with email and password fields.
    • Response: 200 OK on success, 400 Bad Request if the user already exists, or if the request body is invalid.
  • POST /signin: Authenticate a user and generate a JWT token.

    • Request Body: JSON object with email and password fields.
    • Response: 200 OK with a JWT token on success, 401 Unauthorized if the email or password is incorrect.
  • GET /userProfile: Get the user profile.

    • Request Headers: Token with the JWT token obtained after sign-in.
    • Response: 200 OK with the user profile JSON containing the email, 401 Unauthorized if the token is missing or invalid.

Dependencies

Author

Ahmed Mahdi

https://ajm4k.webflow.io

go-json-web-token-example's People

Contributors

ajm4k avatar

Stargazers

 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.