Added test suites for all current models

This commit is contained in:
🐙PiperYxzzy
2022-05-01 20:49:03 +02:00
parent 5f85a5800e
commit 6e7b30be0a
12 changed files with 400 additions and 27 deletions

View File

@@ -4,6 +4,7 @@ import (
"crypto/rand"
"fmt"
"github.com/golang-jwt/jwt"
"github.com/google/uuid"
)
@@ -33,3 +34,19 @@ func SendEmail(title string, body string, recipient string) {
//TODO
fmt.Println("Send", title, body, "to", recipient)
}
func ParseJwt(tokenStr string, hmac []byte) (jwt.MapClaims, error) {
token, err := jwt.Parse(tokenStr, func(token *jwt.Token) (interface{}, error) {
if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok {
return nil, fmt.Errorf("bad signing method %v", token.Header["alg"])
}
return hmac, nil
})
if claims, ok := token.Claims.(jwt.MapClaims); ok && token.Valid {
return claims, nil
} else {
return jwt.MapClaims{}, err
}
}