diff --git a/account/account.go b/account/account.go index 1eb854c..bec4663 100644 --- a/account/account.go +++ b/account/account.go @@ -253,7 +253,7 @@ func (s AccountServiceDefault) PinByID(uploadId uint, accountID uint) error { } func (s AccountServiceDefault) doLogin(user *models.User, ip string) (string, error) { - token, err := GenerateToken(s.config.GetString("core.domain"), s.identity, user.ID, JWTPurposeLogin) + token, err := JWTGenerateToken(s.config.GetString("core.domain"), s.identity, user.ID, JWTPurposeLogin) if err != nil { return "", err } diff --git a/account/jwt.go b/account/jwt.go index cf6654f..f0ebfff 100644 --- a/account/jwt.go +++ b/account/jwt.go @@ -27,11 +27,11 @@ const ( JWTPurpose2FA JWTPurpose = "2fa" ) -func GenerateToken(domain string, privateKey ed25519.PrivateKey, userID uint, purpose JWTPurpose) (string, error) { - return GenerateTokenWithDuration(domain, privateKey, userID, time.Hour*24, purpose) +func JWTGenerateToken(domain string, privateKey ed25519.PrivateKey, userID uint, purpose JWTPurpose) (string, error) { + return JWTGenerateTokenWithDuration(domain, privateKey, userID, time.Hour*24, purpose) } -func GenerateTokenWithDuration(domain string, privateKey ed25519.PrivateKey, userID uint, duration time.Duration, purpose JWTPurpose) (string, error) { +func JWTGenerateTokenWithDuration(domain string, privateKey ed25519.PrivateKey, userID uint, duration time.Duration, purpose JWTPurpose) (string, error) { // Define the claims claims := jwt.RegisteredClaims{ @@ -54,7 +54,7 @@ func GenerateTokenWithDuration(domain string, privateKey ed25519.PrivateKey, use return tokenString, nil } -func VerifyToken(token string, domain string, privateKey ed25519.PrivateKey, verifyFunc VerifyTokenFunc) (*jwt.RegisteredClaims, error) { +func JWTVerifyToken(token string, domain string, privateKey ed25519.PrivateKey, verifyFunc VerifyTokenFunc) (*jwt.RegisteredClaims, error) { validatedToken, err := jwt.ParseWithClaims(token, jwt.RegisteredClaims{}, func(token *jwt.Token) (interface{}, error) { if _, ok := token.Method.(*jwt.SigningMethodEd25519); !ok { return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"]) diff --git a/api/middleware/middleware.go b/api/middleware/middleware.go index 34f543f..2281bc6 100644 --- a/api/middleware/middleware.go +++ b/api/middleware/middleware.go @@ -120,7 +120,7 @@ func AuthMiddleware(options AuthMiddlewareOptions) func(http.Handler) http.Handl return } - claim, err := account.VerifyToken(authToken, domain, options.Identity, func(claim jwt.RegisteredClaims) error { + claim, err := account.JWTVerifyToken(authToken, domain, options.Identity, func(claim jwt.RegisteredClaims) error { aud, _ := claim.GetAudience() if slices.Contains[jwt.ClaimStrings, string](aud, string(options.Purpose)) == false {