コード例 #1
0
        private static void ConfigureIdentityServer(
            IServiceCollection services,
            IConfiguration configuration,
            ILogger logger,
            IHostingEnvironment hostingEnvironment)
        {
            if (hostingEnvironment.EnvironmentName != "Development")
            {
                throw new NotSupportedException($"The Identity Server configuration is currently only intended for Development environments. Current environment: '{hostingEnvironment.EnvironmentName}'");
            }

            var clientSource = new ConfigurationBasedClientSource(logger);
            var clients      = clientSource.LoadClients(configuration.GetSection("Identity:Clients"))
                               .ToList();

            services.AddIdentityServer(options =>
            {
                options.Endpoints.EnableAuthorizeEndpoint = true;
                options.Endpoints.EnableTokenEndpoint     = true;
            })
            .AddTemporarySigningCredential()     // using inbuilt signing cert, but we are explicitly a dev-only service at this point ;-)
            .AddInMemoryClients(clients)
            .AddInMemoryIdentityResources(Scopes.GetIdentityResources())
            .AddInMemoryApiResources(Scopes.GetApiResources())
            .AddExtensionGrantValidator <FacebookUserAccessTokenExtensionGrantValidator>()
            ;
            services.AddTransient <IPasswordHasher, PasswordHasher>();
            services.AddTransient <IProfileService, StoreBackedProfileService>();
            services.AddTransient <IResourceOwnerPasswordValidator, StoreBackedResourceOwnerPasswordValidator>();
            services.AddTransient <UserClaimsProvider>();
        }
        private List <Client> GetClientsFromJson(
            string json,
            bool addEnvironmentVariables     = false,
            string environmentVariablePrefix = null)
        {
            var config = LoadConfig(json, addEnvironmentVariables, environmentVariablePrefix);

            var source  = new ConfigurationBasedClientSource(NullLogger.Instance);
            var clients = source.LoadClients(config.GetSection("Identity:Clients"))
                          .ToList();

            return(clients);
        }
コード例 #3
0
        private static void ConfigureIdentityServer(
            IServiceCollection services,
            IConfiguration configuration,
            ILogger logger,
            IHostingEnvironment hostingEnvironment)
        {
            if (!hostingEnvironment.IsDevelopment())
            {
                throw new NotSupportedException($"The Identity Server configuration is currently only intended for Development environments. Current environment: '{hostingEnvironment.EnvironmentName}'");
            }

            var clientSource = new ConfigurationBasedClientSource(logger);
            var clients      = clientSource.LoadClients(configuration.GetSection("Identity:Clients"))
                               .ToList();

            var identityServerBuilder = services.AddIdentityServer(options =>
            {
                options.Endpoints.EnableAuthorizeEndpoint = true;
                options.Endpoints.EnableTokenEndpoint     = true;
                options.UserInteraction.ErrorUrl          = "/account/error";
            })
                                        .AddTemporarySigningCredential() // using inbuilt signing cert, but we are explicitly a dev-only service at this point ;-)
                                        .AddInMemoryClients(clients)
                                        .AddInMemoryIdentityResources(Scopes.GetIdentityResources())
                                        .AddInMemoryApiResources(Scopes.GetApiResources())
            ;

            // Facebook Sign-in method

            //var facebookUserAccessTokenEnabled = bool.Parse(configuration["Identity:SignInMethods:Facebook:EnableAccessToken"] ?? "false");
            //if (facebookUserAccessTokenEnabled)
            //{
            //    identityServerBuilder.AddExtensionGrantValidator<FacebookUserAccessTokenExtensionGrantValidator>();
            //}

            identityServerBuilder.AddGrantValidatorIfConfigured <FacebookUserAccessTokenExtensionGrantValidator>("Identity:SignInMethods:Facebook:EnableAccessToken", configuration);
            identityServerBuilder.AddGrantValidatorIfConfigured <GuestAccessTokenExtensionGrantValidator>("Identity:SignInMethods:GuestAccess:Enabled", configuration);


            // Guest access token sign-in
            services.AddTransient <IPasswordHasher, PasswordHasher>();
            services.AddTransient <IProfileService, StoreBackedProfileService>();
            services.AddTransient <IResourceOwnerPasswordValidator, StoreBackedResourceOwnerPasswordValidator>();
            services.AddTransient <UserClaimsProvider>();
            services.AddTransient <FacebookGraphService>();
        }