示例#1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddCors(options => options.AddPolicy("AllowAll", p => p.AllowAnyOrigin()
                                                          .AllowAnyMethod()
                                                          .AllowAnyHeader()
                                                          .AllowCredentials()));

            services.AddLibraryContext(Configuration.GetConnectionString("DefaultConnection"));
            services.AddDataProcessingServices();

            services
            .AddEFDataStorage()
            .AddAutoMapper();

            services
            .AddAuthentication(o =>
            {
                o.DefaultScheme             = IdentityServerAuthenticationDefaults.AuthenticationScheme;
                o.DefaultAuthenticateScheme = IdentityServerAuthenticationDefaults.AuthenticationScheme;
            })
            .AddIdentityServerAuthentication(IdentityServerAuthenticationDefaults.AuthenticationScheme, o =>
            {
                o.Authority            = Configuration["Tokens:Authority"];
                o.ApiName              = "api1";
                o.SupportedTokens      = SupportedTokens.Both;
                o.RequireHttpsMetadata = false;
            });

            services.AddAuthorization(options => {
                foreach (var policy in Privileges.GetPrivilegePolicies())
                {
                    options.AddPolicy(policy.Key, policy.Value);
                }
            });



            services.AddMvc();

            services.AddIdentityServer()
            .AddDeveloperSigningCredential()
            .AddInMemoryPersistedGrants()
            .AddInMemoryApiResources(IdentityServerConfig.GetApiResources())
            .AddInMemoryClients(IdentityServerConfig.GetClients())
            .AddAspNetIdentity <User>()
            .AddProfileService <UserProfileService>();
        }