Beispiel #1
0
        // This code configures Web API. The Startup class is specified as a type
        // parameter in the WebApp.Start method.
        public void Configuration(IAppBuilder app)
        {
            // Configura Idendity
            IdentityConfig.ConfigureOAuth(app);

            // Configure Web API for self-host.
            var config = new HttpConfiguration();

            RouteConfig.Register(config);
            app.UseWebApi(config);
        }
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbContext <IdentityContext>(config =>
            {
                config.UseSqlServer(IdentityGlobalConfig.ConnectionString);
            });
            services.AddIdentity <IdentityUser, IdentityRole>(config =>
            {
                config.Password.RequireDigit           = false;
                config.Password.RequiredLength         = 2;
                config.Password.RequireLowercase       = false;
                config.Password.RequireUppercase       = false;
                config.Password.RequireNonAlphanumeric = false;
            })
            .AddEntityFrameworkStores <IdentityContext>();


            services.AddIdentityServer()
            .AddDeveloperSigningCredential(filename: "tempkey.rsa")
            .AddInMemoryApiResources(IdentityConfig.GetApiResources())
            .AddInMemoryIdentityResources(IdentityConfig.GetIdentityResources())
            .AddInMemoryClients(IdentityConfig.GetClients())
            .AddTestUsers(IdentityConfig.GetUsers());

            services.AddMvc().AddMvcOptions(options => options.EnableEndpointRouting = false);

            services.Configure <DataProtectionTokenProviderOptions>(o =>
                                                                    o.TokenLifespan = TimeSpan.FromHours(3));

            services.AddTransient <IdentityContext, IdentityContext>()
            .AddTransient <IdentityService, IdentityApiController>();

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo {
                    Title = "Identity.Amazon", Version = "v1"
                });
            });
        }