bearer,context: support hash verification of the computed args

This commit is contained in:
Michael Muré
2024-11-27 12:23:56 +01:00
committed by Michael Muré
parent 4c25456583
commit 6f4853cd2f

View File

@@ -2,27 +2,26 @@ package server
import "context" import "context"
type contextKey string type ctxUserIdKey struct{}
var ctxUserId = contextKey("userId")
var ctxProjectId = contextKey("projectId")
// ContextGetUserId return the UserId stored in the context, if it exists. // ContextGetUserId return the UserId stored in the context, if it exists.
func ContextGetUserId(ctx context.Context) (string, bool) { func ContextGetUserId(ctx context.Context) (string, bool) {
val, ok := ctx.Value(ctxUserId).(string) val, ok := ctx.Value(ctxUserIdKey{}).(string)
return val, ok return val, ok
} }
func addUserIdToContext(ctx context.Context, userId string) context.Context { func addUserIdToContext(ctx context.Context, userId string) context.Context {
return context.WithValue(ctx, ctxUserId, userId) return context.WithValue(ctx, ctxUserIdKey{}, userId)
} }
type ctxProjectIdKey struct{}
// ContextGetProjectId return the ProjectID stored in the context, if it exists. // ContextGetProjectId return the ProjectID stored in the context, if it exists.
func ContextGetProjectId(ctx context.Context) (string, bool) { func ContextGetProjectId(ctx context.Context) (string, bool) {
val, ok := ctx.Value(ctxProjectId).(string) val, ok := ctx.Value(ctxProjectIdKey{}).(string)
return val, ok return val, ok
} }
func addProjectIdToContext(ctx context.Context, projectId string) context.Context { func addProjectIdToContext(ctx context.Context, projectId string) context.Context {
return context.WithValue(ctx, ctxProjectId, projectId) return context.WithValue(ctx, ctxProjectIdKey{}, projectId)
} }