MCPcopy Create free account
hub / github.com/APIParkLab/APIPark / Handler

Method Handler

plugins/openapi/check.go:49–85  ·  view source on GitHub ↗
(ginCtx *gin.Context)

Source from the content-addressed store, hash-verified

47}
48
49func (o *openapiCheck) Handler(ginCtx *gin.Context) {
50 notIgnore := !ignore.IsIgnorePath("openapi", ginCtx.Request.Method, ginCtx.FullPath())
51 if !notIgnore {
52 return
53 }
54 authorization := ginCtx.GetHeader("Authorization")
55 if authorization == "" {
56 apikey, has := ginCtx.GetQuery("apikey")
57 if !has {
58 ginCtx.AbortWithStatusJSON(403, gin.H{"code": -8, "msg": "invalid token", "success": "fail"})
59 return
60 }
61 authorization = apikey
62 }
63 authorization = strings.TrimPrefix(authorization, "Bearer ")
64 if authorization == o.apikey {
65 return
66 }
67 list, err := o.apikeyModule.SimpleList(ginCtx)
68 if err != nil {
69 ginCtx.AbortWithStatusJSON(403, gin.H{"code": -8, "msg": "invalid token", "success": "fail"})
70 return
71 }
72 if len(list) == 0 {
73 ginCtx.AbortWithStatusJSON(403, gin.H{"code": -8, "msg": "invalid token", "success": "fail"})
74 return
75 }
76 for _, item := range list {
77 if item.Value == authorization {
78 if item.Expired != 0 && item.Expired < time.Now().Unix() {
79 continue
80 }
81 return
82 }
83 }
84 ginCtx.AbortWithStatusJSON(403, gin.H{"code": -8, "msg": "invalid token", "success": "fail"})
85}

Callers

nothing calls this directly

Calls 1

SimpleListMethod · 0.65

Tested by

no test coverage detected