mirror of
https://git.freecumextremist.com/grumbulon/pomme.git
synced 2024-11-22 15:43:47 +00:00
25 lines
503 B
Go
25 lines
503 B
Go
package api
|
|
|
|
import (
|
|
"log"
|
|
|
|
"git.freecumextremist.com/grumbulon/pomme/internal"
|
|
"github.com/go-chi/jwtauth/v5"
|
|
)
|
|
|
|
var tokenAuth *jwtauth.JWTAuth
|
|
|
|
func init() {
|
|
if config, err := internal.ReadConfig(); err == nil {
|
|
tokenAuth = jwtauth.New("HS256", []byte(config.HashingSecret), nil)
|
|
}
|
|
}
|
|
|
|
func makeToken(username string) string {
|
|
_, tokenString, err := tokenAuth.Encode(map[string]interface{}{"username": username, "admin": "false"})
|
|
if err != nil {
|
|
log.Fatalln(err)
|
|
}
|
|
|
|
return tokenString
|
|
}
|