예제 #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure <IdentitySettings>(Configuration);
            var settings = Configuration.Get <IdentitySettings>();

            services.AddSingleton(settings);

            services.AddIdentityServer
            (
                options =>
            {
                options.IssuerUri = settings.IdentityEndPoint;
                options.Endpoints.EnableDiscoveryEndpoint = true;
                options.Endpoints.EnableTokenEndpoint     = true;
                options.Endpoints.EnableUserInfoEndpoint  = true;

                options.Endpoints.EnableAuthorizeEndpoint       = false;
                options.Endpoints.EnableCheckSessionEndpoint    = false;
                options.Endpoints.EnableEndSessionEndpoint      = false;
                options.Endpoints.EnableIntrospectionEndpoint   = false;
                options.Endpoints.EnableTokenRevocationEndpoint = false;
            }
            )
            .AddDeveloperSigningCredential()
            .AddInMemoryApiResources(IdentityConfiguration.GetApiResources(settings))
            .AddInMemoryClients(IdentityConfiguration.GetClients(settings));

            services.AddMvc();
        }
예제 #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbContext <AuthDbContext>(options =>
                                                  options.UseSqlServer(Configuration.GetConnectionString("IdentityConnection")));
            services.AddControllers();
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo {
                    Title = "TodoApp.Identity", Version = "v1"
                });
            });

            services.AddIdentity <ApplicationUser, IdentityRole>()
            .AddEntityFrameworkStores <AuthDbContext>()
            //.AddClaimsPrincipalFactory<CustomUserClaimsPrincipalFactory>();
            .AddDefaultTokenProviders();     // Что это делает?

            services.AddIdentityServer(options => options.IssuerUri = "localhost")
            .AddInMemoryApiResources(IdentityConfiguration.GetApiResources())
            .AddInMemoryIdentityResources(IdentityConfiguration.GetIdentityResources())
            .AddInMemoryApiScopes(IdentityConfiguration.GetScopes())
            .AddInMemoryClients(IdentityConfiguration.GetClients())
            .AddAspNetIdentity <ApplicationUser>()
            .AddProfileService <ProfileService>()
            .AddDeveloperSigningCredential(false);

            services.AddAuthentication()
            .AddGoogle("Google", options =>
            {
                options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme;

                options.ClientId     = "631863314589-78e0flbpm57l2rg6gi6h7meunj68f4in.apps.googleusercontent.com";
                options.ClientSecret = "LfOYActB2UPuPmW9sho7c_zi";
            });

            services.AddTransient <IUserClaimsPrincipalFactory <ApplicationUser>, CustomUserClaimsPrincipalFactory>();

            services.AddCors(options => {
                options.AddPolicy("default", policy =>
                {
                    policy.WithOrigins("http://localhost:3000")
                    .AllowAnyHeader()
                    .AllowAnyMethod()
                    .AllowCredentials();
                });
            });
        }
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddCors(options =>
            {
                options.AddPolicy("AllowAll",
                                  builder => builder
                                  .AllowAnyMethod()
                                  .AllowAnyOrigin()
                                  .AllowAnyHeader());
            });

            services.Configure <IdentitySettings>(Configuration);
            var settings = Configuration.Get <IdentitySettings>();

            services.AddSingleton(settings);

            services.AddIdentityServer
            (
                options =>
            {
                //options.Cors = new CorsOptions{};
                options.IssuerUri = settings.IdentityEndPoint;
                options.Endpoints.EnableDiscoveryEndpoint = true;
                options.Endpoints.EnableTokenEndpoint     = true;
                options.Endpoints.EnableUserInfoEndpoint  = true;

                options.Endpoints.EnableAuthorizeEndpoint       = false;
                options.Endpoints.EnableCheckSessionEndpoint    = false;
                options.Endpoints.EnableEndSessionEndpoint      = false;
                options.Endpoints.EnableIntrospectionEndpoint   = false;
                options.Endpoints.EnableTokenRevocationEndpoint = false;
            }
            )
            //.AddDeveloperSigningCredential()
            .AddDeveloperSigningCredential()
            .AddInMemoryApiResources(IdentityConfiguration.GetApiResources(settings))
            .AddInMemoryClients(IdentityConfiguration.GetClients(settings));

            services.AddMvc();
        }
예제 #4
0
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            //IdentityConfiguration.Configuration = Configuration;

            services.AddDbContext <TestDBContext>();

            services.AddAutoMapper();

            services.AddIdentityServer()
            .AddDeveloperSigningCredential()
            .AddInMemoryIdentityResources(IdentityConfiguration.GetIdentityResources())
            .AddInMemoryApiResources(IdentityConfiguration.GetApiResources())
            .AddInMemoryClients(IdentityConfiguration.GetClients())
            .AddResourceOwnerValidator <ResourceOwnerPasswordValidator>()
            .AddProfileService <ProfileService>();

            var builder = new ContainerBuilder();

            builder.RegisterModule <UtilModule>();
            builder.RegisterModule <ServiceModule>();
            builder.Populate(services);
            ApplicationContainer = builder.Build();
            return(new AutofacServiceProvider(ApplicationContainer));
        }
예제 #5
0
        public static void AddIdentityServerConfig(this IServiceCollection services, IConfiguration configuration, IHostingEnvironment env)
        {
            services.AddIdentity <User, IdentityRole>()
            .AddEntityFrameworkStores <ShopContext>()
            .AddDefaultTokenProviders();

            services.AddIdentityServer()
            .AddDeveloperSigningCredential()
            .AddInMemoryPersistedGrants()
            .AddInMemoryIdentityResources(IdentityConfiguration.GetIdentityResources())
            .AddInMemoryApiResources(IdentityConfiguration.GetApiResources())
            .AddInMemoryClients(IdentityConfiguration.GetClients())
            .AddAspNetIdentity <User>();

            services.AddTransient <IProfileService, IdentityProfileService>();

            services.Configure <IdentityOptions>(config =>
            {
                config.Password.RequireDigit           = true;
                config.Password.RequiredLength         = 8;
                config.Password.RequireUppercase       = false;
                config.Password.RequireNonAlphanumeric = false;
            });

            services.AddAuthentication(options =>
            {
                options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                options.DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme;
            })
            .AddJwtBearer(options =>
            {
                options.Authority            = configuration["ID4:Authority"];
                options.Audience             = configuration["ID4:Audience"];
                options.RequireHttpsMetadata = false;
            });
        }