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) {
|
func(w http.ResponseWriter, r *http.Request) {
|
||||||
ctx := r.Context()
|
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, "")
|
tokenValue, err := securetoken.Get(r, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
next.ServeHTTP(w, r)
|
next.ServeHTTP(w, r)
|
||||||
@@ -60,6 +54,12 @@ func NewAPIKeyMiddleware(svc *iam.Service) func(next http.Handler) http.Handler
|
|||||||
return
|
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)
|
apiKey, err := svc.APIKeyService.GetAPIKey(ctx, keyID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
var errUserAPIKeyNotFound *iam.ErrUserAPIKeyNotFound
|
var errUserAPIKeyNotFound *iam.ErrUserAPIKeyNotFound
|
||||||
|
|||||||
@@ -49,12 +49,6 @@ func NewSessionMiddleware(svc *iam.Service, cookieConfig securecookie.Config) fu
|
|||||||
func(w http.ResponseWriter, r *http.Request) {
|
func(w http.ResponseWriter, r *http.Request) {
|
||||||
ctx := r.Context()
|
ctx := r.Context()
|
||||||
|
|
||||||
apiKey := APIKeyFromContext(ctx)
|
|
||||||
if apiKey != nil {
|
|
||||||
httpserver.RenderError(w, http.StatusBadRequest, errors.New("session authentication cannot be used with API key authentication"))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
cookieValue, err := securecookie.Get(r, cookieConfig)
|
cookieValue, err := securecookie.Get(r, cookieConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
next.ServeHTTP(w, r)
|
next.ServeHTTP(w, r)
|
||||||
@@ -68,6 +62,12 @@ func NewSessionMiddleware(svc *iam.Service, cookieConfig securecookie.Config) fu
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
apiKey := APIKeyFromContext(ctx)
|
||||||
|
if sessionID != gid.Nil && apiKey != nil {
|
||||||
|
httpserver.RenderError(w, http.StatusBadRequest, errors.New("session authentication cannot be used with API key authentication"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
session, err := svc.SessionService.GetSession(ctx, sessionID)
|
session, err := svc.SessionService.GetSession(ctx, sessionID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
var errSessionNotFound *iam.ErrSessionNotFound
|
var errSessionNotFound *iam.ErrSessionNotFound
|
||||||
|
|||||||
Reference in New Issue
Block a user