Categorygithub.com/SatvikR/jwt-auth-go
repositorypackage
0.0.0-20210612034648-88143cddb697
Repository: https://github.com/satvikr/jwt-auth-go.git
Documentation: pkg.go.dev

# README

JWT Auth Go

This is an example implementation of JWT auth in Go. This should NOT be used in production. This should only be used as a reference when building your own authentication system.

This implements JWT auth using two token types: Access and Refresh. The refresh tokens are stored as http only cookies, and the access tokens should be stored in memory on a frontend client.

Config

Setup postgresql database

CREATE DATABASE somedbname;

Connect to the database and run:

CREATE EXTENSION IF NOT EXISTS "uuid-ossp";

Create a .env file with six variables

ACCESS_TOKEN_SECRET=
REFRESH_TOKEN_SECRET=
DB_ADDR=
DB_USER=
DB_PASSWORD=
DB_NAME=

Routes

MethodRouteData RequiredReturns
POST/signupBody: { "username": "", "password": "" }accessToken (exp in 15 seconds)
POST/loginBody: { "username": "", "password": "" }accessToken (exp in 15 seconds)
GET/meHeader: Authorization: Bearer tokenHereYour username
PUT/refreshNew accessToken (exp in 15 seconds)
DELETE/logoutDeletes token, sends back status

License: MIT