mirror of
https://git.freecumextremist.com/grumbulon/pomme.git
synced 2024-11-16 20:34:11 +00:00
29 lines
612 B
Go
29 lines
612 B
Go
package api
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
|
|
"dns.froth.zone/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) (tokenString string, err error) {
|
|
claim := map[string]interface{}{"username": username, "admin": false}
|
|
|
|
jwtauth.SetExpiry(claim, time.Now().Add(time.Hour))
|
|
|
|
if _, tokenString, err = tokenAuth.Encode(claim); err == nil {
|
|
return
|
|
}
|
|
|
|
return "", fmt.Errorf("unable to generate JWT: %w", err)
|
|
}
|