MCPcopy Create free account
hub / github.com/TalkingData/owl / AuthMySQL

Function AuthMySQL

api/auth.go:56–85  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

54}
55
56func AuthMySQL() gin.HandlerFunc {
57 return func(c *gin.Context) {
58 var (
59 tokenString string
60 token *jwt.Token
61 err error
62 link string
63 )
64 tokenString, _ = c.Cookie("token")
65 if token, err = ValidateToken(tokenString); err != nil {
66 c.SetCookie("token", "", -1, "/", "", false, true)
67 c.AbortWithStatusJSON(http.StatusOK, gin.H{"code": http.StatusUnauthorized, "link": link, "message": err.Error()})
68 return
69 }
70 claims, ok := token.Claims.(jwt.MapClaims)
71 if !ok {
72 c.AbortWithStatus(http.StatusInternalServerError)
73 return
74 }
75 if username, ok := claims["email"]; ok {
76 if user := mydb.getUserProfile(username.(string)); user == nil {
77 c.AbortWithStatusJSON(http.StatusOK, gin.H{"code": http.StatusUnauthorized, "message": "user not found"})
78 c.SetCookie("token", "", -1, "/", "", false, true)
79 return
80 }
81 c.Set("username", username)
82 }
83 c.Next()
84 }
85}
86
87func JudgePermission(actionName string, username string, appID string, apiKey string) bool {
88 url := fmt.Sprintf("%s/permission?action=%s&username=%s", strings.TrimRight(config.IamURL, "/"), actionName, username)

Callers 1

InitServerFunction · 0.85

Calls 3

ValidateTokenFunction · 0.85
getUserProfileMethod · 0.80
SetMethod · 0.80

Tested by

no test coverage detected