AuthAPIKey middleware to authenticate API key
()
| 28 | |
| 29 | // AuthAPIKey middleware to authenticate API key |
| 30 | func (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 | } |
no test coverage detected