hostname-service/auth/auth.go

22 lines
477 B
Go

package auth
import (
"time"
"git.beisel.it/florian/hostname-service/config"
"github.com/dgrijalva/jwt-go"
)
func GenerateToken(username string) (string, error) {
expirationTime := time.Now().Add(1 * time.Hour)
claims := &jwt.StandardClaims{
Subject: username,
ExpiresAt: expirationTime.Unix(),
}
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
tokenString, err := token.SignedString(config.JwtKey)
return tokenString, err
}