Пример #1
0
        private async Task <AegisTenant> CreateAegisTenant(string tenantKey)
        {
            var tenant = await _tenantManager.GetByKeyAsync(tenantKey);

            if (tenant == null)
            {
                return(CreateEmptyTenant());
            }

            // A normalized version of Tenant.Id is scope each auth requests per tenant
            var normalizedTenantId = tenant.Id.ToLower().Replace("-", "");

            // Initialize base context
            var aegisTenant = new AegisTenant()
            {
                TenantId  = tenant.Id,
                TenantKey = tenant.Key,

                AuthSchemeInternal = "aegis.internal." + normalizedTenantId,
                AuthSchemeExternal = "aegis.external." + normalizedTenantId,
            };


            //
            // Configure Identity Server Connection for this Tenant
            //
            var connectClient = new ConnectClient();

            var signinRedirectUris = await _tenantManager.GetUrisAsync(tenantKey, TenantUriType.OidcSignin);

            var logoutRedirectUris = await _tenantManager.GetUrisAsync(tenantKey, TenantUriType.OidcPostLogout);

            connectClient.SetSigninRedirectUris(signinRedirectUris);
            connectClient.SetPostLogoutRedirectUris(logoutRedirectUris);

            aegisTenant.Clients = new List <IdentityServer4.Models.Client> {
                connectClient
            };


            //
            // Configure Password Options
            // TODO: Persist password options per client. (Using defaults for now).
            //

            aegisTenant.PasswordOptions = _serverDefaults.OpenId.Password;


            //
            // Configure External Auth Providers
            // TODO: Persist auth providers per client. (Using defaults for now).
            //

            aegisTenant.ProviderOptions = _serverDefaults.OpenId.Providers;

            if (aegisTenant.ProviderOptions?.Facebook != null)
            {
                aegisTenant.ProviderOptions.Facebook.AuthScheme = "aegis.external.facebook." + tenantKey;
            }

            if (aegisTenant.ProviderOptions?.Google != null)
            {
                aegisTenant.ProviderOptions.Google.AuthScheme = "aegis.external.google." + tenantKey;
            }

            if (aegisTenant.ProviderOptions?.Twitter != null)
            {
                aegisTenant.ProviderOptions.Twitter.AuthScheme = "aegis.external.twitter." + tenantKey;
            }

            if (aegisTenant.ProviderOptions?.Microsoft != null)
            {
                aegisTenant.ProviderOptions.Microsoft.AuthScheme = "aegis.external.microsoft." + tenantKey;
            }


            //
            // Configure Custom UI Elements
            //

            aegisTenant.SiteTitle  = tenant.OidcTitle;
            aegisTenant.SiteBanner = tenant.OidcBanner ?? "/img/default-banner.png";

            return(await Task.FromResult(aegisTenant));
        }