MCPcopy
hub / github.com/apache/answer / AuthAPIKey

Method AuthAPIKey

internal/base/middleware/api_key_auth.go:30–51  ·  view source on GitHub ↗

AuthAPIKey middleware to authenticate API key

()

Source from the content-addressed store, hash-verified

28
29// AuthAPIKey middleware to authenticate API key
30func (am *AuthUserMiddleware) AuthAPIKey() gin.HandlerFunc {
31 return func(ctx *gin.Context) {
32 token := ExtractToken(ctx)
33 if len(token) == 0 {
34 handler.HandleResponse(ctx, errors.Unauthorized(reason.UnauthorizedError), nil)
35 ctx.Abort()
36 return
37 }
38 pass, err := am.authService.AuthAPIKey(ctx, ctx.Request.Method == "GET", token)
39 if err != nil {
40 handler.HandleResponse(ctx, errors.Unauthorized(reason.UnauthorizedError), nil)
41 ctx.Abort()
42 return
43 }
44 if !pass {
45 handler.HandleResponse(ctx, errors.Unauthorized(reason.UnauthorizedError), nil)
46 ctx.Abort()
47 return
48 }
49 ctx.Next()
50 }
51}

Callers 2

AuthAPIKeyScopeMethod · 0.45
NewHTTPServerFunction · 0.45

Calls 2

HandleResponseFunction · 0.92
ExtractTokenFunction · 0.85

Tested by

no test coverage detected