Fix collision between connect API key & Session middlewares
Signed-off-by: Émile Ré <nemile.re@gmail.com>
This commit is contained in:
@@ -42,12 +42,6 @@ func NewAPIKeyMiddleware(svc *iam.Service) func(next http.Handler) http.Handler
|
||||
func(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
|
||||
session := SessionFromContext(ctx)
|
||||
if session != nil {
|
||||
httpserver.RenderError(w, http.StatusBadRequest, errors.New("api key authentication cannot be used with session authentication"))
|
||||
return
|
||||
}
|
||||
|
||||
tokenValue, err := securetoken.Get(r, "")
|
||||
if err != nil {
|
||||
next.ServeHTTP(w, r)
|
||||
@@ -60,6 +54,12 @@ func NewAPIKeyMiddleware(svc *iam.Service) func(next http.Handler) http.Handler
|
||||
return
|
||||
}
|
||||
|
||||
session := SessionFromContext(ctx)
|
||||
if keyID != gid.Nil && session != nil {
|
||||
httpserver.RenderError(w, http.StatusBadRequest, errors.New("api key authentication cannot be used with session authentication"))
|
||||
return
|
||||
}
|
||||
|
||||
apiKey, err := svc.APIKeyService.GetAPIKey(ctx, keyID)
|
||||
if err != nil {
|
||||
var errUserAPIKeyNotFound *iam.ErrUserAPIKeyNotFound
|
||||
|
||||
Reference in New Issue
Block a user