Esempio n. 1
0
    public static void AddZNxtSSO(this IServiceCollection services, IWebHostEnvironment environment)
    {
        if (!ApplicationConfig.IsSSO)
        {
            return;
        }
        services.Configure <IISOptions>(options =>
        {
            options.AutomaticAuthentication   = false;
            options.AuthenticationDisplayName = "Windows";
        });

        var builder = services.AddIdentityServer(options =>
        {
            options.Events.RaiseErrorEvents       = true;
            options.Events.RaiseInformationEvents = true;
            options.Events.RaiseFailureEvents     = true;
            options.Events.RaiseSuccessEvents     = true;
            options.UserInteraction = new UserInteractionOptions()
            {
                LogoutUrl = "/account/logout",
                LoginUrl  = "/account/login",
                LoginReturnUrlParameter = "returnUrl"
            };
        })
                      .AddTestUsers(TestUsers.Users);

        // in-memory, code config
        builder.AddInMemoryIdentityResources(SSOConfig.GetIdentityResources());
        builder.AddInMemoryApiResources(SSOConfig.GetApis());
        //builder.AddInMemoryClients(SSOConfig.GetClients());
        builder.AddClientStore <ClientStore>();
        if (environment.IsDevelopment())
        {
            builder.AddDeveloperSigningCredential();
        }
        else
        {
            var fileName = Path.Combine(environment.ContentRootPath, "ZNxtIdentitySigning.pfx");
            var cert     = new X509Certificate2(fileName, "abc@123");
            builder.AddSigningCredential(cert);
        }
        //services.AddAuthentication()
        //    .AddGoogle(options =>
        //    {
        //        options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme;
        //        options.ClientId = "592081696184-3056k8j98cfliger0398q08nmi50cfjs.apps.googleusercontent.com";
        //        options.ClientSecret = "l-vFpRQvyZP_otetPhrF5Xdy";
        //    });
        services.AddTransient <IZNxtUserService, ZNxtUserService>();
        services.AddTransient <IProfileService, ZNxtProfileService>();
        services.AddTransient <ZNxtUserStore>();
        services.AddTransient <IUserNotifierService, UserNotifierService>();
        services.AddTransient <IResourceOwnerPasswordValidator, ZNxtResourceOwnerPasswordValidator>();
        services.AddTransient <ITenantSetterService, TenantSetterService>();
    }
Esempio n. 2
0
        public virtual OAuthClient GetClient(string clientId)
        {
            var client = _inMemoryCacheService.Get <OAuthClient>($"{cachePrefix}{clientId}");

            if (client == null)
            {
                var cln = SSOConfig.GetClients().FirstOrDefault(f => f.ClientId == clientId);
                if (cln != null)
                {
                    client = new OAuthClient {
                        Client = cln
                    };
                }
            }
            if (client == null)
            {
                client = FetchClient(clientId);
            }
            return(client);
        }