This is an automated email from the ASF dual-hosted git repository. lahirujayathilake pushed a commit to branch auth-endpoints in repository https://gitbox.apache.org/repos/asf/airavata-custos.git
commit fb26181c68037d238fc710c8ab31abc1af52d04f Author: lahiruj <[email protected]> AuthorDate: Tue Jun 16 19:16:45 2026 -0400 Wire auth and CORS middleware into the server entrypoint --- cmd/server/main.go | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/cmd/server/main.go b/cmd/server/main.go index 2287f100c..2f716d45c 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -38,6 +38,7 @@ import ( "github.com/apache/airavata-custos/internal/connectors" "github.com/apache/airavata-custos/internal/db" "github.com/apache/airavata-custos/internal/server" + "github.com/apache/airavata-custos/internal/server/middleware" "github.com/apache/airavata-custos/internal/store" "github.com/apache/airavata-custos/internal/tracing" "github.com/apache/airavata-custos/pkg/events" @@ -143,7 +144,14 @@ func run() error { return err } - handler := server.LoggingMiddleware(srv) + userIdentityStore := store.NewUserIdentityStore(database) + auth, err := middleware.NewAuth(cfg.Core.Auth, resolveUserBySub(userIdentityStore), + middleware.WithSkipPrefixes("/healthz")) + if err != nil { + return err + } + cors := middleware.NewCORS(cfg.Core.CORS) + handler := server.LoggingMiddleware(cors.Wrap(auth.Wrap(srv))) httpServer := &http.Server{ Addr: addr, @@ -215,6 +223,19 @@ func envInt(key string, fallback int) int { return n } +func resolveUserBySub(userIdentityStore store.UserIdentityStore) middleware.UserResolver { + return func(ctx context.Context, sub string) (string, error) { + ui, err := userIdentityStore.FindByOIDCSub(ctx, sub) + if err != nil { + return "", err + } + if ui == nil { + return "", nil + } + return ui.UserID, nil + } +} + func applyLogLevel(level string) { var lvl slog.Level switch strings.ToLower(strings.TrimSpace(level)) {
