MCPcopy Create free account
hub / github.com/MertJSX/folderhost / VerifyToken

Function VerifyToken

utils/jwt.go:25–49  ·  view source on GitHub ↗
(tokenString string, secretKey string)

Source from the content-addressed store, hash-verified

23}
24
25func VerifyToken(tokenString string, secretKey string) (string, error) {
26 token, err := jwt.Parse(tokenString, func(token *jwt.Token) (interface{}, error) {
27 return []byte(secretKey), nil
28 })
29
30 if err != nil {
31 return "", err
32 }
33
34 if !token.Valid {
35 return "", fmt.Errorf("invalid token")
36 }
37
38 claims, ok := token.Claims.(jwt.MapClaims)
39 if !ok {
40 return "", fmt.Errorf("invalid token claims")
41 }
42
43 username, ok := claims["username"].(string)
44 if !ok {
45 return "", fmt.Errorf("username not found in token")
46 }
47
48 return username, nil
49}

Callers 2

CheckAuthFunction · 0.92
WsConnectFunction · 0.92

Calls

no outgoing calls

Tested by

no test coverage detected