Skip to content

Commit

Permalink
fix: get auth claims as map
Browse files Browse the repository at this point in the history
  • Loading branch information
ochom committed Jan 14, 2024
1 parent b684acf commit 015940d
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions helpers/auth.go → auth/auth.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package helpers
package auth

import (
"time"

"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 {
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
Expand Down

0 comments on commit 015940d

Please sign in to comment.