From 015940dc4e567e09485d21f38e3ecdbaeb2e2caf Mon Sep 17 00:00:00 2001 From: ochom Date: Sun, 14 Jan 2024 15:15:02 +0300 Subject: [PATCH] fix: get auth claims as map --- {helpers => auth}/auth.go | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) rename {helpers => auth}/auth.go (86%) diff --git a/helpers/auth.go b/auth/auth.go similarity index 86% rename from helpers/auth.go rename to auth/auth.go index a39b90e..5fe4ccc 100644 --- a/helpers/auth.go +++ b/auth/auth.go @@ -1,4 +1,4 @@ -package helpers +package auth import ( "time" @@ -6,10 +6,7 @@ import ( "github.com/golang-jwt/jwt" ) -// getAuthSecrete ... -func getAuthSecrete() string { - return GetEnv("AUTH_SECRET_KEY", "secrete") -} +var authSecrete string = "secrete" // authClaims is the struct that will be encoded to a JWT. type authClaims struct { @@ -36,7 +33,7 @@ func GenerateAuthTokens(data map[string]string, tokenExpiry ...time.Duration) (s Issuer: "ochom", } - token, err := jwt.NewWithClaims(jwt.SigningMethodHS256, claims).SignedString([]byte(getAuthSecrete())) + token, err := jwt.NewWithClaims(jwt.SigningMethodHS256, claims).SignedString([]byte(authSecrete)) if err != nil { return "", "", err } @@ -46,7 +43,7 @@ func GenerateAuthTokens(data map[string]string, tokenExpiry ...time.Duration) (s Issuer: "ochom", } - refreshToken, err := jwt.NewWithClaims(jwt.SigningMethodHS256, claims).SignedString([]byte(getAuthSecrete())) + refreshToken, err := jwt.NewWithClaims(jwt.SigningMethodHS256, claims).SignedString([]byte(authSecrete)) if err != nil { return "", "", err } @@ -58,7 +55,7 @@ func GenerateAuthTokens(data map[string]string, tokenExpiry ...time.Duration) (s func GetAuthClaims(token string) (map[string]string, error) { claims := &authClaims{} tkn, err := jwt.ParseWithClaims(token, claims, func(token *jwt.Token) (interface{}, error) { - return []byte(getAuthSecrete()), nil + return []byte(authSecrete), nil }) if err != nil { return nil, err