Documentation ¶
Index ¶
- Constants
- Variables
- func ExtractTenantIDFromContext(ctx context.Context) (string, error)
- func ExtractTenantIDFromHeaders(ctx context.Context, headers http.Header) (string, context.Context, error)
- func InjectTenantID(ctx context.Context, tenantID string) context.Context
- func NewAuthInterceptor(enabled bool) connect.Interceptor
- type AllowedTenants
Constants ¶
const DefaultTenantID = "anonymous"
DefaultTenantID is the default tenant ID used when the interceptor is disabled.
Variables ¶
var ErrNoTenantID = user.ErrNoOrgID
Functions ¶
func ExtractTenantIDFromContext ¶
ExtractTenantIDFromContext extracts a single TenantID from the context.
func ExtractTenantIDFromHeaders ¶
func ExtractTenantIDFromHeaders(ctx context.Context, headers http.Header) (string, context.Context, error)
ExtractTenantIDFromHeaders extracts a single TenantID from http headers.
func NewAuthInterceptor ¶
func NewAuthInterceptor(enabled bool) connect.Interceptor
NewAuthInterceptor create a new tenant authentication interceptor for the server and client.
For the server:
If enabled, the interceptor will check the tenant ID in the request header is present and inject it into the context. When the interceptor is disabled, it will inject the default tenant ID into the context.
For the client :
The interceptor will inject the tenant ID from the context into the request header no matter if the interceptor is enabled or not.
Types ¶
type AllowedTenants ¶ added in v1.2.0
type AllowedTenants struct {
// contains filtered or unexported fields
}
AllowedTenants that can answer whether tenant is allowed or not based on configuration. Default value (nil) allows all tenants.
func NewAllowedTenants ¶ added in v1.2.0
func NewAllowedTenants(enabled []string, disabled []string) *AllowedTenants
NewAllowedTenants builds new allowed tenants based on enabled and disabled tenants. If there are any enabled tenants, then only those tenants are allowed. If there are any disabled tenants, then tenant from that list, that would normally be allowed, is disabled instead.
func (*AllowedTenants) IsAllowed ¶ added in v1.2.0
func (a *AllowedTenants) IsAllowed(tenantID string) bool