Exemplo n.º 1
0
        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");
            }
        }
Exemplo n.º 2
0
    /// <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);
    }
Exemplo n.º 3
0
        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);
        }