feat: add tenant authorization middleware
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
package membership
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"proxui/backend/internal/rbac"
|
||||
)
|
||||
|
||||
type Membership struct {
|
||||
TenantID string `json:"tenant_id"`
|
||||
Role rbac.Role `json:"role"`
|
||||
}
|
||||
|
||||
type contextKey struct{}
|
||||
|
||||
func ContextWithMembership(ctx context.Context, membership Membership) context.Context {
|
||||
return context.WithValue(ctx, contextKey{}, membership)
|
||||
}
|
||||
|
||||
func FromContext(ctx context.Context) (Membership, bool) {
|
||||
membership, ok := ctx.Value(contextKey{}).(Membership)
|
||||
return membership, ok
|
||||
}
|
||||
|
||||
func FromRequest(r *http.Request) (Membership, bool) {
|
||||
return FromContext(r.Context())
|
||||
}
|
||||
Reference in New Issue
Block a user