private static void SetTenantFor(IIdentityContext identityContext, HttpContext httpContext) { var tenantId = TenantResolver.Resolver(httpContext); if (!identityContext.HasAssociatedTenant && !string.IsNullOrEmpty(tenantId)) { identityContext.SetCurrentTenant(long.Parse(tenantId)); } else { throw new Exception("Tenant cannot be identified"); } }
/// <inheritdoc/> public Task Execute(IntegrationMessage message, CancellationToken cancellationToken) { if (!_identityContext.HasAssociatedTenant) { var tenantId = message .GetMetadata(TenantIdMetadataKey) .ToNullableLong(); _logger.LogInformationIfEnabled( "Extracted {TenantId} tenant id from message {MessageId}", tenantId, message.Id); if (tenantId.HasValue) { _identityContext.SetCurrentTenant(tenantId.Value); } } return(Task.CompletedTask); }
public async Task InvokeAsync(HttpContext context, IIdentityContext identityContext) { if (!ExcludePath(context)) { string?tenantId = TenantResolver.Resolver(context); if (!string.IsNullOrEmpty(tenantId)) { identityContext.SetCurrentTenant(long.Parse(tenantId)); } else { context.Response.StatusCode = (int)HttpStatusCode.Unauthorized; await context.Response.WriteAsync("Unable to identify tenant"); return; } } await _next(context); }