You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
Matthieu Lamalle 8d8bdd175a correct env vars 3 years ago
cmd/jwtserver update conf var names 3 years ago
internal/router set uuid and refresh token path 3 years ago
middleware correct env vars 3 years ago
misc/containers/postgres first commit 3 years ago
.env.dist update conf var names 3 years ago
.gitignore first commit 3 years ago
Makefile first commit 3 years ago
README.md typo markdown 3 years ago
api.http set uuid and refresh token path 3 years ago
docker-compose.yml first commit 3 years ago
go.mod set uuid and refresh token path 3 years ago
go.sum set uuid and refresh token path 3 years ago
jwt.go update package 3 years ago
jwtserver update internal path 3 years ago

README.md

Go-JWTServer

Go-JWTServer met a disposition :

  • Un serveur de stockage de utilisateur sous postgres et d'authenfication Jwt
  • Un middleware d'authentification Jwt

Serveur

Configuration

Editer le ficher .env

## Server
web_adress=":3001"

## Postgres
db_user="jwtserver"
db_pass="jwtserver"
db_name="jwtserver"
db_host="localhost"

## JWT
token_password="NotSoSecretJwtSecretPassword"

Executer le serveur

Lancer le conteneur postgres

make up

Dans une autre console, lancer le serveur jwt

make run

Middleware

Le middleware permet d'enregistrer et d'authentifier un utilisateur et de vérifier la validité du token Jwt

Exemple
  r := chi.NewRouter()

  //add Jwt Authentification
  r.Use(jwtmiddleware.JwtAuthentication)

  .Route("/api/", func(r chi.Router) {
    //Middleware routes
    r.Post("/user/new", jwtmiddleware.CreateAccount)
    r.Post("/user/login", jwtmiddleware.Authenticate)
  })

API

Enregistrer un utilisateur
POST {{host}}/api/user/new 
content-type: application/json

{
    "email": "test@test.com",
    "password": "test"
}
Authentifier un utilisateur
POST {{host}}/api/user/login 
content-type: application/json

{
    "email": "test@test.com",
    "password": "test"
}
Réponse
{
  "account": {
    "ID": 1,
    "CreatedAt": "2020-07-15T14:08:22.288502Z",
    "UpdatedAt": "2020-07-15T14:08:22.288502Z",
    "DeletedAt": null,
    "email": "test@test.com",
    "password": "",
    "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJVc2VySWQiOjF9.-bV_jRNcykDMsI-vjxKbiNBsEwqSfDspEEjBTE2nds8"
  },
  "message": "Logged In",
  "status": true
}