コード例 #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>();
        }
コード例 #2
0
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddAuthentication();

        var builder = services.AddIdentityServer(options =>
        {
            options.IssuerUri = "https://idsvr4";

            options.Events = new EventsOptions
            {
                RaiseErrorEvents       = true,
                RaiseFailureEvents     = true,
                RaiseInformationEvents = true,
                RaiseSuccessEvents     = true
            };
            options.KeyManagement.Enabled = false;
        });

        builder.AddInMemoryClients(Clients.Get());
        builder.AddInMemoryIdentityResources(Scopes.GetIdentityScopes());
        builder.AddInMemoryApiResources(Scopes.GetApiResources());
        builder.AddInMemoryApiScopes(Scopes.GetApiScopes());

        builder.AddDeveloperSigningCredential(persistKey: false);

        services.AddTransient <IResourceOwnerPasswordValidator, CustomResponseResourceOwnerValidator>();
        builder.AddExtensionGrantValidator <CustomResponseExtensionGrantValidator>();
    }
コード例 #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>();
        }
コード例 #4
0
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddAuthentication();

        var builder = services.AddIdentityServer(options =>
        {
            options.IssuerUri = "https://idsvr4";

            options.Events = new EventsOptions
            {
                RaiseErrorEvents       = true,
                RaiseFailureEvents     = true,
                RaiseInformationEvents = true,
                RaiseSuccessEvents     = true
            };
            options.KeyManagement.Enabled = false;
        });

        builder.AddInMemoryClients(Clients.Get());
        builder.AddInMemoryIdentityResources(Scopes.GetIdentityScopes());
        builder.AddInMemoryApiResources(Scopes.GetApiResources());
        builder.AddInMemoryApiScopes(Scopes.GetApiScopes());
        builder.AddTestUsers(Users.Get());

        builder.AddDeveloperSigningCredential(persistKey: false);

        builder.AddExtensionGrantValidator <ExtensionGrantValidator>();
        builder.AddExtensionGrantValidator <ExtensionGrantValidator2>();
        builder.AddExtensionGrantValidator <NoSubjectExtensionGrantValidator>();
        builder.AddExtensionGrantValidator <DynamicParameterExtensionGrantValidator>();

        builder.AddProfileService <CustomProfileService>();

        builder.AddJwtBearerClientAuthentication();
        builder.AddSecretValidator <ConfirmationSecretValidator>();

        // add a custom token request validator if set
        if (CustomTokenRequestValidator != null)
        {
            builder.Services.AddTransient(r => CustomTokenRequestValidator);
        }
    }