Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions rpc/access/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ func accessKeyMiddleware(next http.Handler) http.Handler {
if accessKey != "" {
ctx = tenant.WithAccessKey(ctx, accessKey)
}
origin := r.Header.Get("origin")
if origin != "" {
ctx = tenant.WithOrigin(ctx, origin)
}
next.ServeHTTP(w, r.WithContext(ctx))
})
}
Expand Down
10 changes: 10 additions & 0 deletions rpc/tenant/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type contextKeyType string

var (
accessKeyCtxKey = contextKeyType("access-key")
originKeyCtxKey = contextKeyType("origin")
tenantCtxKey = contextKeyType("tenant-data")
)

Expand All @@ -26,3 +27,12 @@ func AccessKeyFromContext(ctx context.Context) string {
func WithAccessKey(ctx context.Context, accessKey string) context.Context {
return context.WithValue(ctx, accessKeyCtxKey, accessKey)
}

func OriginFromContext(ctx context.Context) string {
v, _ := ctx.Value(originKeyCtxKey).(string)
return v
}

func WithOrigin(ctx context.Context, origin string) context.Context {
return context.WithValue(ctx, originKeyCtxKey, origin)
}
6 changes: 4 additions & 2 deletions rpc/waasapi/waasapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ func Context(ctx context.Context, optJwtToken ...string) context.Context {
waasHeader := http.Header{}
waasHeader.Set("Authorization", "BEARER "+jwtToken)

accessKey := tenant.AccessKeyFromContext(ctx)
if accessKey != "" {
if accessKey := tenant.AccessKeyFromContext(ctx); accessKey != "" {
waasHeader.Set("X-Access-Key", accessKey)
}
if origin := tenant.OriginFromContext(ctx); origin != "" {
waasHeader.Set("Origin", origin)
}

waasCtx, err := proto_wallet.WithHTTPRequestHeaders(ctx, waasHeader)
if err != nil {
Expand Down