Go-gin-jwt - Secure web api using jwt token and caching mechanism

Overview

Project Description

This project demonstrate how to create api and secure it with jwt token. The project also has capability of caching mechanism using redis. I've implemented clean architecture in this project that contains 4 layers namely repository, usecase, delivery and entity. If you are interested to the architecture that i have implemented, you can refer to this article : https://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html

Endpoint

  • /api/auth/login(public)
  • /api/auth/logout(require token)
  • /api/user(require token)

Usecase

  • When user login, user will passing 2 required field namely username and password, actually in this project I haven't implemented sql database. This project only focus how to secure api using jwt and how the caching mechanism using redis. App will receive the username and password and compare it with the username and password that i have harcoded in the code. If the credential is matched, then app will generate token and store the user uuid generated by app to redis.
  • When user access private endpoint, user must provide Authorization header. App will validate that token. Before validating the token, the app will check whether that token is owned by logged user by checking the user uuid is exist or not in redis. So there is no way we can use token from logged out user
  • When user logout, app will remove user uuid from redis.

How to run this project ?

You need to provide .env file that has these variable

APP_NAME=
JWT_SIGNATURE_KEY=
REDIS_HOST=
REDIS_PORT=
API_HOST=
API_PORT=

Download project dependencies

go mod tidy

run the project

go run .

Requirements

  • Redis version >= 5.0.7
  • Go version >= go1.17.3
Owner
Jeremy Panjaitan
Jeremy Panjaitan
Account-jwt-go - Simple JWT api with go, gorm, gin

Account JWT on Go Go, gorm, Gin web framework 를 활용하여 만든 간단한 JWT API 입니다. Dajngo의

Deagwon Bu 1 Apr 14, 2022
This package provides json web token (jwt) middleware for goLang http servers

jwt-auth jwt auth middleware in goLang. If you're interested in using sessions, checkout my sessions library! README Contents: Quickstart Performance

Adam Hanna 218 Jul 29, 2022
Backend Development Rest Api Project for book management system. Used Features like redis, jwt token,validation and authorization.

Golang-restapi-project Simple Rest Api Project with Authentication, Autherization,Validation and Connection with redis File Structure ├── cache │ ├──

Srijan Chakraborty 1 May 25, 2022
auth0 jwt validator with jwks caching

JWT Validator for Auth0 (https://auth0.com/) that caches public JWKS (since there is a limit on calls to public JWKS URL) Example securing a GraphQL s

null 0 Mar 4, 2022
Golang implementation of JWT and Refresh Token

Fiber and JWT with Refresh Token Repo ini adalah demostrasi JWT support refresh token tanpa menggunakan storage Branch Main: unlimited refresh token R

Muhamad Surya Iksanudin 16 Aug 13, 2022
Small Lambda function which performs a Aws:Sts:AssumeRole based on the presented JWT-Token

About This implements a AWS Lambda handler which takes a JWT-Token, validates it and then performs a Aws:Sts:AssumeRole based on preconfigured rules.

AOE 5 Aug 8, 2022
A command-line tool to visualize a JWT token's content, written in Go

jat A command-line tool to visualize a JWT token's content, written in Go. Usage jat <some-jwt> Install Navigate to the Releases page; Download the co

Matheus Calegaro 1 Jan 6, 2022
Verifier - Golang JWT token verifier with storage(default Redis)

verifier Golang JWT token verifier with storage(default Redis) Usage go get -u g

XanderCheung 7 Jul 1, 2022
:key: Secure alternative to JWT. Authenticated Encrypted API Tokens for Go.

branca branca is a secure alternative to JWT, This implementation is written in pure Go (no cgo dependencies) and implements the branca token specific

Wesley Hill 168 Aug 7, 2022
Fast, secure and efficient secure cookie encoder/decoder

Encode and Decode secure cookies This package provides functions to encode and decode secure cookie values. A secure cookie has its value ciphered and

Christophe Meessen 60 Jul 6, 2022
Golang with JWT, Go Gin and MongoDB

User authentication in Golang with JWT, Go Gin and MongoDB Golang backend application that uses JWT tokens for users Locally Up Setup your .env file,

Al Mamun Khan 10 May 27, 2022
JSON Web Token library

About … a JSON Web Token (JWT) library for the Go programming language. Feature complete Full test coverage Dependency free Key management The API enf

Pascal S. de Kloe 291 Aug 8, 2022
JWT wrapper library which makes it simple to use ECDSA based JWT signing

JWT JWT wrapper library which makes it simple to user ECDSA based JWT signing. Usage package main import ( "context" "github.com/infiniteloopcloud

infinite loop 0 Feb 10, 2022
Krakend-jwt-header-rewriter - Kraken Plugin - JWT Header Rewriter

Kraken Plugin - JWT Header Rewriter 1 Plugin Configuration Name Desciption Defau

null 0 Feb 15, 2022
A single sign-on solution based on go-oauth2 / oauth2 and gin-gonic/gin

A single sign-on solution based on go-oauth2 / oauth2 and gin-gonic/gin

yinhuanyi 1 Nov 17, 2021
A demo using go and redis to implement a token manager

使用go-redis实现一个令牌管理器 需求描述 假设我们当前的所有服务需要一个第三方的认证,认证形式为:在发送请求的时候带上第三方颁发的令牌,该令牌具有一个时效性 第三方的令牌可以通过某个接口获取,但是该接口做了单位时间内的同一ip的请求频率的限制,因此在并发的场景下,我们需要控制令牌获取接口的频

Yuki Chen 0 Oct 19, 2021
Go module that allows you to authenticate to Azure with a well known client ID using interactive logon and grab the token

azureimposter Go module that pretends to be any clientID and grabs an authentication token from Azure using interactive login (w/mfa if enabled) and r

Lars Karlslund 22 Jun 23, 2022
jwt package for gin go applications

gin-jwt jwt package for gin go applications Usage Download using go module: go get github.com/ennaque/gin-jwt Import it in your code: import gwt "gith

Igor Volkov 2 Apr 21, 2022
This is a jwt for Gin framework.

JWT for Gin Framework This is a jwt useful for Gin framework. It uses jwt-go to provide a jwt encode and decode token. Usage go get github.com/wyy-go/

null 0 Jan 9, 2022