Refactor marketplace product fetching and caching logic; update environment configuration for Redis and PostgreSQL
This commit is contained in:
31
pkg/utils/utils.go
Executable file → Normal file
31
pkg/utils/utils.go
Executable file → Normal file
@@ -1 +1,32 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/golang-jwt/jwt/v5"
|
||||
)
|
||||
|
||||
type WbAuthData struct {
|
||||
Token string `json:"token"`
|
||||
}
|
||||
|
||||
func NewWbAuthData(token string) WbAuthData {
|
||||
return WbAuthData{
|
||||
Token: token,
|
||||
}
|
||||
}
|
||||
|
||||
func DecodeWildberriesJwt(token []byte) (WbAuthData, jwt.MapClaims, error) {
|
||||
var authData WbAuthData
|
||||
err := json.Unmarshal(token, &authData)
|
||||
if err != nil {
|
||||
return authData, nil, fmt.Errorf("failed to unmarshal JWT: %w", err)
|
||||
}
|
||||
claims := jwt.MapClaims{}
|
||||
_, _, err = jwt.NewParser().ParseUnverified(authData.Token, claims)
|
||||
if err != nil {
|
||||
return authData, nil, fmt.Errorf("invalid JWT: %w", err)
|
||||
}
|
||||
|
||||
return authData, claims, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user