Exemplo n.º 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();
            services.AddMvcCore().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

            var builder = services.AddIdentityServer(options =>
            {
                options.Events.RaiseErrorEvents       = true;
                options.Events.RaiseInformationEvents = true;
                options.Events.RaiseFailureEvents     = true;
                options.Events.RaiseSuccessEvents     = true;
            })
                          .AddInMemoryClients(InMemoryClients.GetClients())
                          .AddInMemoryIdentityResources(InMemoryIdentityResources.GetIdentityResources())
                          .AddInMemoryApiResources(InMemoryApiResources.GetApiResources());

            if (Environment.IsDevelopment())
            {
                builder.AddDeveloperSigningCredential();
            }
            else
            {
                builder.AddSigningCredential(new SigningCredentials(new RsaSecurityKey(new RSACryptoServiceProvider(2048)), SecurityAlgorithms.RsaSha256Signature));
            }

            services.AddAuthentication();
        }
Exemplo n.º 2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var connectionStr = Configuration.GetConnectionString("DefaultConnection");

            var migrationAssembly = this.GetType().GetTypeInfo().Assembly.GetName().Name;

            services.AddDbContext <AutenticacaoDbContext>(options => { options.UseSqlServer(connectionStr, sqlOptions => sqlOptions.MigrationsAssembly(migrationAssembly)); });

            services
            .AddIdentityServer()
            .AddOperationalStore(options => { options.ConfigureDbContext = x => x.UseSqlServer(connectionStr, sqlOptions => sqlOptions.MigrationsAssembly(migrationAssembly)); })
            //  .AddConfigurationStore(options => { options.ConfigureDbContext = x => x.UseSqlServer(connectionStr, sqlOptions => sqlOptions.MigrationsAssembly(migrationAssembly)); })
            .AddProfileService <ContaProfileService>()
            .AddResourceOwnerValidator <ContaPasswordValidator>()
            .AddInMemoryApiResources(InMemoryResources.GetAPIResources())
            .AddInMemoryIdentityResources(InMemoryResources.GetIdentityResources())
            .AddInMemoryClients(InMemoryClients.GetClients())
            .AddDeveloperSigningCredential();
        }