Skip to content

Commit

Permalink
http-gateway: return http.Unauthenticated for invalid JWT
Browse files Browse the repository at this point in the history
  • Loading branch information
jkralik committed Oct 26, 2023
1 parent 384c8f4 commit b55e96d
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions http-gateway/serverMux/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@ package serverMux

import (
"context"
"fmt"
"net/http"

router "github.com/gorilla/mux"
"github.com/plgd-dev/hub/v2/pkg/net/grpc"
kitHttp "github.com/plgd-dev/hub/v2/pkg/net/http"
"google.golang.org/grpc/codes"
)

// NewRouter creates router with default middlewares
func NewRouter(queryCaseInsensitive map[string]string, authInterceptor kitHttp.Interceptor, opts ...kitHttp.LogOpt) *router.Router {
r := router.NewRouter()
r.Use(kitHttp.CreateLoggingMiddleware(opts...))
r.Use(kitHttp.CreateAuthMiddleware(authInterceptor, func(ctx context.Context, w http.ResponseWriter, r *http.Request, err error) {
WriteError(w, fmt.Errorf("cannot access to %v: %w", r.RequestURI, err))
WriteError(w, grpc.ForwardErrorf(codes.Unauthenticated, "cannot access to %v: %w", r.RequestURI, err))
}))
r.Use(kitHttp.CreateMakeQueryCaseInsensitiveMiddleware(queryCaseInsensitive, opts...))
r.Use(kitHttp.CreateTrailSlashSuffixMiddleware(opts...))
Expand Down

0 comments on commit b55e96d

Please sign in to comment.