diff --git a/api/server/handlers/user/migrate.go b/api/server/handlers/user/migrate.go index 21ef4114aa7..db2a1b030a2 100644 --- a/api/server/handlers/user/migrate.go +++ b/api/server/handlers/user/migrate.go @@ -1,7 +1,6 @@ package user import ( - "context" "fmt" "net/http" "strconv" @@ -127,7 +126,7 @@ func (u *MigrateUsersHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) continue } - createdIdentity, _, err := u.Config().Ory.IdentityAPI.CreateIdentity(context.WithValue(ctx, ory.ContextAccessToken, u.Config().OryApiKey)).CreateIdentityBody(createIdentityBody).Execute() + createdIdentity, _, err := u.Config().Ory.IdentityAPI.CreateIdentity(u.Config().OryApiKeyContextWrapper(ctx)).CreateIdentityBody(createIdentityBody).Execute() if err != nil { migrationErrors[user.ID] = fmt.Sprintf("error creating identity: %s", err.Error()) continue diff --git a/api/server/shared/config/config.go b/api/server/shared/config/config.go index 2b752ba0d0d..87cfadd3c96 100644 --- a/api/server/shared/config/config.go +++ b/api/server/shared/config/config.go @@ -1,6 +1,8 @@ package config import ( + "context" + "github.com/gorilla/sessions" ory "github.com/ory/client-go" "github.com/porter-dev/api-contracts/generated/go/porter/v1/porterv1connect" @@ -122,8 +124,8 @@ type Config struct { TelemetryConfig telemetry.TracerConfig - Ory *ory.APIClient - OryApiKey string + Ory *ory.APIClient + OryApiKeyContextWrapper func(ctx context.Context) context.Context } type ConfigLoader interface { diff --git a/api/server/shared/config/loader/loader.go b/api/server/shared/config/loader/loader.go index acefa742a63..a58d05bcabc 100644 --- a/api/server/shared/config/loader/loader.go +++ b/api/server/shared/config/loader/loader.go @@ -1,6 +1,7 @@ package loader import ( + "context" "encoding/base64" "errors" "fmt" @@ -396,7 +397,9 @@ func (e *EnvConfigLoader) LoadConfig() (res *config.Config, err error) { }} res.Ory = ory.NewAPIClient(c) - res.OryApiKey = InstanceEnvConf.ServerConf.OryApiKey + res.OryApiKeyContextWrapper = func(ctx context.Context) context.Context { + return context.WithValue(ctx, ory.ContextAccessToken, InstanceEnvConf.ServerConf.OryApiKey) + } return res, nil }