func (m *UserManager) CheckToken(jwtSecret, tokenStr string) (TokenClaims, bool) {
	claims := &TokenClaims{}
	tkn, err := jwt.ParseWithClaims(tokenStr, claims, func(token *jwt.Token) (interface{}, error) {
		return []byte(jwtSecret), nil
	})
	if err != nil {
		log.Printf("Error %v", err)
		return *claims, false
	}
	if !tkn.Valid {
		log.Println("Not valid")
		return *claims, false
	}
	return *claims, true
}
CheckToken to verify if a token used is valid
package users
import (
	"encoding/json"
	"fmt"
	"log"
	"time"
	"github.com/golang-jwt/jwt/v4"
	"github.com/jinzhu/gorm"
	"github.com/jinzhu/gorm/dialects/postgres"
	"github.com/jmpsec/osctrl/types"
	"golang.org/x/crypto/bcrypt"
)
type AdminUser struct {
	gorm.Model
	Username      string `gorm:"index"`
	Email         string
	Fullname      string
	PassHash      string
	APIToken      string
	TokenExpire   time.Time
	Admin         bool
	DefaultEnv    string
	CSRFToken     string
	Permissions   postgres.Jsonb
	LastIPAddress string
	LastUserAgent string
	LastAccess    time.Time
	LastTokenUse  time.Time
}
type TokenClaims struct {
	Username string `json:"username"`
	jwt.StandardClaims
}
type UserManager struct {
	DB        *gorm.DB
	JWTConfig *types.JSONConfigurationJWT
}
func CreateUserManager(backend *gorm.DB, jwtconfig *types.JSONConfigurationJWT) *UserManager {
	var u *UserManager
	u = &UserManager{DB: backend, JWTConfig: jwtconfig}
	if err := backend.AutoMigrate(AdminUser{}).Error; err != nil {
		log.Fatalf("Failed to AutoMigrate table (admin_users): %v", err)
	}
	return u
}
func (m *UserManager) HashTextWithSalt(text string) (string, error) {
	saltedBytes := []byte(text)
	hashedBytes, err := bcrypt.GenerateFromPassword(saltedBytes, bcrypt.DefaultCost)
	if err != nil {
		return "", err
	}
	hash := string(hashedBytes)
	return hash, nil
}
func (m *UserManager) HashPasswordWithSalt(password string) (string, error) {
	return m.HashTextWithSalt(password)
}
func (m *UserManager) CheckLoginCredentials(username, password string) (bool, AdminUser) {
	user, err := m.Get(username)
	if err != nil {
		return false, AdminUser{}
	}
	p := []byte(password)
	existing := []byte(user.PassHash)
	err = bcrypt.CompareHashAndPassword(existing, p)
	if err != nil {
		return false, AdminUser{}
	}
	return true, user
}
func (m *UserManager) CreateToken(username string) (string, time.Time, error) {
	expirationTime := time.Now().Add(time.Hour * time.Duration(m.JWTConfig.HoursToExpire))
	claims := &TokenClaims{
		Username: username,
		StandardClaims: jwt.StandardClaims{
			ExpiresAt: expirationTime.Unix(),
			Issuer:    "admin",
		},
	}
	token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
	tokenString, err := token.SignedString([]byte(m.JWTConfig.JWTSecret))
	if err != nil {
		return "", time.Now(), err
	}
	return tokenString, expirationTime, nil
}