diff --git a/context.go b/context.go index cf3ea8e..48e2f6a 100644 --- a/context.go +++ b/context.go @@ -45,8 +45,10 @@ func GetSessionType(ctx context.Context) (proto.SessionType, bool) { // Account // -// withAccount adds the account to the context. -func withAccount(ctx context.Context, account string) context.Context { +// WithAccount adds the account to the context. +// +// Deprecated: this will be removed in the future, use Session middleware with a JWT token. +func WithAccount(ctx context.Context, account string) context.Context { return context.WithValue(ctx, ctxKeyAccount, account) } @@ -60,8 +62,10 @@ func GetAccount(ctx context.Context) (string, bool) { // User // -// withUser adds the user to the context. -func withUser(ctx context.Context, user any) context.Context { +// WithUser adds the user to the context. +// +// Deprecated: this will be removed in the future, use Session middleware with a JWT token. +func WithUser(ctx context.Context, user any) context.Context { return context.WithValue(ctx, ctxKeyUser, user) } @@ -90,8 +94,10 @@ func GetService(ctx context.Context) (string, bool) { // AccessKey // -// withAccessKey adds the access key to the context. -func withAccessKey(ctx context.Context, accessKey string) context.Context { +// WithAccessKey adds the access key to the context. +// +// Deprecated: this will be removed in the future, use Session middleware with a JWT token. +func WithAccessKey(ctx context.Context, accessKey string) context.Context { return context.WithValue(ctx, ctxKeyAccessKey, accessKey) } @@ -105,8 +111,10 @@ func GetAccessKey(ctx context.Context) (string, bool) { // Project ID // -// withProjectID adds the project to the context. -func withProjectID(ctx context.Context, project uint64) context.Context { +// WithProjectID adds the project to the context. +// +// Deprecated: this will be removed in the future, use Session middleware with a JWT token. +func WithProjectID(ctx context.Context, project uint64) context.Context { return context.WithValue(ctx, ctxKeyProjectID, project) } diff --git a/middleware.go b/middleware.go index d0ebfd6..e2c419e 100644 --- a/middleware.go +++ b/middleware.go @@ -79,7 +79,7 @@ func Session(cfg *Options) func(next http.Handler) http.Handler { ctx = WithService(ctx, serviceClaim) sessionType = proto.SessionType_Service case accountClaim != "": - ctx = withAccount(ctx, accountClaim) + ctx = WithAccount(ctx, accountClaim) sessionType = proto.SessionType_Wallet if cfg != nil && cfg.UserStore != nil { @@ -90,7 +90,7 @@ func Session(cfg *Options) func(next http.Handler) http.Handler { } if user != nil { - ctx = withUser(ctx, user) + ctx = WithUser(ctx, user) sessionType = proto.SessionType_User if isAdmin { @@ -105,14 +105,14 @@ func Session(cfg *Options) func(next http.Handler) http.Handler { if projectClaim > 0 { projectID := uint64(projectClaim) - ctx = withProjectID(ctx, projectID) + ctx = WithProjectID(ctx, projectID) sessionType = proto.SessionType_Project } } } if accessKey != "" && sessionType < proto.SessionType_Admin { - ctx = withAccessKey(ctx, accessKey) + ctx = WithAccessKey(ctx, accessKey) sessionType = max(sessionType, proto.SessionType_AccessKey) }