@@ -26,6 +26,7 @@ import (
2626 "github.com/go-chi/chi/v5/middleware"
2727
2828 v1 "github.com/stacklok/toolhive/pkg/api/v1"
29+ "github.com/stacklok/toolhive/pkg/auth"
2930 "github.com/stacklok/toolhive/pkg/container"
3031 "github.com/stacklok/toolhive/pkg/lifecycle"
3132 "github.com/stacklok/toolhive/pkg/logger"
@@ -78,14 +79,29 @@ func cleanupUnixSocket(address string) {
7879// Serve starts the server on the given address and serves the API.
7980// It is assumed that the caller sets up appropriate signal handling.
8081// If isUnixSocket is true, address is treated as a UNIX socket path.
81- func Serve (ctx context.Context , address string , isUnixSocket bool , debugMode bool , enableDocs bool ) error {
82+ // If oidcConfig is provided, OIDC authentication will be enabled for all API endpoints.
83+ func Serve (
84+ ctx context.Context ,
85+ address string ,
86+ isUnixSocket bool ,
87+ debugMode bool ,
88+ enableDocs bool ,
89+ oidcConfig * auth.JWTValidatorConfig ,
90+ ) error {
8291 r := chi .NewRouter ()
8392 r .Use (
8493 middleware .RequestID ,
8594 // TODO: Figure out logging middleware. We may want to use a different logger.
8695 middleware .Timeout (middlewareTimeout ),
8796 )
8897
98+ // Add authentication middleware
99+ authMiddleware , err := auth .GetAuthenticationMiddleware (ctx , oidcConfig )
100+ if err != nil {
101+ return fmt .Errorf ("failed to create authentication middleware: %v" , err )
102+ }
103+ r .Use (authMiddleware )
104+
89105 manager , err := lifecycle .NewManager (ctx )
90106 if err != nil {
91107 logger .Panicf ("failed to create lifecycle manager: %v" , err )
0 commit comments