Added test suites for all current models
This commit is contained in:
17
util/util.go
17
util/util.go
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user