/// <summary>
        /// The method that gets invoked by the ASP.NET pipeline
        /// </summary>
        /// <param name="context"><see cref="HttpContext"/> for the request</param>
        public async Task Invoke(HttpContext context)
        {
            var gatewayRequest = GatewayHttpRequest.ParseFromHttpContext(context);

            var handler = await _handlerProvider.GetHandlerAsync(context, gatewayRequest.Tenant.Value.ToString());

            if (handler != null)
            {
                await _next(context);

                return;
            }

            HandleIfTenantDoesNotExist(gatewayRequest.Tenant);

            var tenant = _tenantConfiguration.GetFor(gatewayRequest.Tenant);

            HandleIfTenantHasNoApplication(tenant, gatewayRequest.Application);

            gatewayRequest.SetEtag();

            gatewayRequest.ModifyRequest(_hostingEnvironment.IsDevelopment());

            AuthContextBindings.AuthContext = new Read.AuthContext(tenant, tenant.Applications[gatewayRequest.Application]);

            await _next(gatewayRequest.Context);
        }
Exemplo n.º 2
0
        public IActionResult ExternalLogin(
            [FromQuery] string tenant,
            [FromQuery] string authority,
            [FromQuery] string returnUrl)
        {
            var  tenantName = string.Empty;
            Guid tenantId   = Guid.Empty;
            var  hasTenant  = Guid.TryParse(tenant, out tenantId);

            if (hasTenant)
            {
                var tenantConfiguration = _tenants.GetFor(tenantId);
                if (tenantConfiguration != null)
                {
                    tenantName = tenantConfiguration.Name;
                }
            }

            var properties = new AuthenticationProperties
            {
                RedirectUri = Url.Action("ExternalLoginCallback"),

                Items =
                {
                    { "tenant",     tenant     },
                    { "tenantName", tenantName },
                    { "scheme",     authority  },
                    { "returnUrl",  returnUrl  },
                }
            };

            return(Challenge(properties, authority));
        }