// This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // Для пользователей
            services.AddDbContext <SqlDbContext>(options =>
                                                 options.UseSqlServer(Configuration.GetConnectionString("MainConnection")));


            services.AddControllers().AddNewtonsoftJson();
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo {
                    Title = "IdentityServer4_implementation", Version = "v1"
                });
            });
            services.AddIdentityServer(options => options.IssuerUri = "localhost")
            .AddInMemoryApiResources(ClientStore.GetApiResources())
            .AddInMemoryApiScopes(ClientStore.GetApiScopes())
            .AddInMemoryIdentityResources(ClientStore.GetIdentityResources())
            .AddInMemoryClients(ClientStore.GetClients())
            .AddProfileService <ProfileService>()
            //.AddTestUsers(Users.GetTestUsers())
            .AddDeveloperSigningCredential(false);
            services.AddTransient <ITokenProvider, TokenProvider>();
            services.AddScoped <IUserRepository, UserRepository>();

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

                options.ClientId     = "434483408261-55tc8n0cs4ff1fe21ea8df2o443v2iuc.apps.googleusercontent.com";
                options.ClientSecret = "3gcoTrEDPPJ0ukn_aYYT6PWo";
                options.CallbackPath = "/signin-google";
            });

            // Для пользователей
            services.AddTransient <IResourceOwnerPasswordValidator, ResourceOwnerPasswordValidator>();
            services.AddTransient <IProfileService, ProfileService>();
        }
示例#2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers().AddNewtonsoftJson();

            services.AddTransient <ITokenProvider, TokenProvider>();
            //services.AddTransient<IResourceOwnerPasswordValidator, ResourceOwnerPasswordValidator>();
            ClientStore.AuthURL     = Configuration["AuthURL"];
            ClientStore.AuthUserURL = Configuration["AuthUserURL"];


            services.AddIdentityServer(options => options.IssuerUri = "localhost")
            .AddInMemoryApiResources(ClientStore.GetApiResources())
            .AddInMemoryIdentityResources(ClientStore.GetIdentityResources())
            .AddInMemoryClients(ClientStore.GetClients())
            .AddDeveloperSigningCredential();

            //services.AddAuthentication(options =>
            //{
            //    options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;
            //    options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
            //    options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
            //})
            //.AddJwtBearer(options =>
            //{
            //    options.TokenValidationParameters = new TokenValidationParameters
            //    {
            //        ValidateAudience = false,
            //        ValidateLifetime = true,
            //        LifetimeValidator = (notBefore, expires, securityToken, validationParameter) =>
            //    expires >= DateTime.UtcNow
            //    };

            //    options.RequireHttpsMetadata = false;
            //    options.Authority = "http://localhost:5000";
            //});
        }