update readme
This commit is contained in:
parent
ef96cadb2e
commit
17ae90ec05
48
README.md
48
README.md
|
@ -1,10 +1,13 @@
|
||||||
# Go-JWTServer
|
# Go-JWTServer
|
||||||
|
|
||||||
Serveur de gestion d'utilisateur et fournissant un token jwt.
|
Go-JWTServer met a disposition :
|
||||||
|
- Un serveur de stockage de utilisateur sous postgres et d'authenfication Jwt
|
||||||
|
- Un middleware d'authentification Jwt
|
||||||
|
|
||||||
Dépendances: docker, docker-compose
|
Dépendances: docker, docker-compose
|
||||||
|
## Serveur
|
||||||
|
|
||||||
## Configuration
|
### Configuration
|
||||||
Editer le ficher `.env`
|
Editer le ficher `.env`
|
||||||
|
|
||||||
```
|
```
|
||||||
|
@ -21,8 +24,35 @@ db_host="localhost"
|
||||||
token_password="NotSoSecretJwtSecretPassword"
|
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
|
## API
|
||||||
#### Enregistrer un utilisateur
|
##### Enregistrer un utilisateur
|
||||||
```
|
```
|
||||||
POST {{host}}/api/user/new
|
POST {{host}}/api/user/new
|
||||||
content-type: application/json
|
content-type: application/json
|
||||||
|
@ -32,7 +62,7 @@ content-type: application/json
|
||||||
"password": "test"
|
"password": "test"
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
#### Authentifier un utilisateur
|
##### Authentifier un utilisateur
|
||||||
```
|
```
|
||||||
POST {{host}}/api/user/login
|
POST {{host}}/api/user/login
|
||||||
content-type: application/json
|
content-type: application/json
|
||||||
|
@ -42,7 +72,7 @@ content-type: application/json
|
||||||
"password": "test"
|
"password": "test"
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
#### Réponse
|
##### Réponse
|
||||||
```
|
```
|
||||||
{
|
{
|
||||||
"account": {
|
"account": {
|
||||||
|
@ -58,11 +88,3 @@ content-type: application/json
|
||||||
"status": true
|
"status": true
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Executer le serveur
|
|
||||||
Lancer le conteneur postgres
|
|
||||||
```make up```
|
|
||||||
|
|
||||||
|
|
||||||
Dans une autre console, lancer le serveur jwt
|
|
||||||
```make run```
|
|
|
@ -15,6 +15,7 @@ func InitializeRouter() chi.Router {
|
||||||
r.Use(middleware.Logger)
|
r.Use(middleware.Logger)
|
||||||
r.Use(middleware.Recoverer)
|
r.Use(middleware.Recoverer)
|
||||||
r.Use(middleware.URLFormat)
|
r.Use(middleware.URLFormat)
|
||||||
|
r.Use(jwtmiddleware.JwtAuthentication)
|
||||||
|
|
||||||
r.Use(middleware.Timeout(60 * time.Second))
|
r.Use(middleware.Timeout(60 * time.Second))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue