Example #1
0
        public void ConfigureServices(IServiceCollection services)
        {
            var migrationAssembly = typeof(Startup).GetTypeInfo().Assembly.GetName().Name;

            const string sqlString = @"server=127.0.0.1; port=65350 database =IdentityServer4Config; Integrated Security=true;";

            services.AddIdentityServer(opt =>
            {
                opt.Authentication.CookieLifetime = TimeSpan.FromMinutes(1);
            })
            //.AddInMemoryApiScopes(InMemoryConfig.GetApiScopes())
            //.AddInMemoryApiResources(InMemoryConfig.GetApiResources())
            //.AddInMemoryIdentityResources(InMemoryConfig.GetIdentityResources())
            //.AddInMemoryClients(InMemoryConfig.GetClients())
            //.AddProfileService<CustomProfileService>()
            .AddTestUsers(InMemoryConfig.GetUsers())
            .AddDeveloperSigningCredential()
            .AddConfigurationStore(opt =>
            {
                opt.ConfigureDbContext = c => c.UseNpgsql(sqlString,
                                                          sql => sql.MigrationsAssembly(migrationAssembly));
            })
            .AddOperationalStore(opt =>
            {
                opt.ConfigureDbContext = o => o.UseNpgsql(sqlString,
                                                          sql => sql.MigrationsAssembly(migrationAssembly));
            });

            services.AddControllersWithViews();
        }
Example #2
0
        public void ConfigureServices(IServiceCollection services)
        {
            // Includes Authentication/Authorization
            services
            .AddIdentityServer()
            .AddInMemoryApiResources(InMemoryConfig.GetApis()) // For basic demonstration, we are going to persist APIs in memory.
            .AddInMemoryClients(InMemoryConfig.GetClients())   // Same here we but for Clients in memory. Ideally these are really persisted / comes from a database/store.
            .AddDeveloperSigningCredential();                  // will add a local key to sign tokens - ONLY DEV

            // Without anything else
            // This url will currently be working.
            //https://localhost:5001/.well-known/openid-configuration

#if DEBUG
            services
            .AddControllersWithViews(
                options =>
            {
                options.SuppressAsyncSuffixInActionNames = true;
            })
            .AddRazorRuntimeCompilation();
#else
            services
            .AddControllersWithViews();
#endif
        }
Example #3
0
            public Task IsActiveAsync(IsActiveContext context)
            {
                var sub  = context.Subject.GetSubjectId();
                var user = InMemoryConfig.GetUsers()
                           .Find(u => u.SubjectId.Equals(sub));

                context.IsActive = user != null;
                return(Task.CompletedTask);
            }
Example #4
0
            public Task GetProfileDataAsync(ProfileDataRequestContext context)
            {
                var sub  = context.Subject.GetSubjectId();
                var user = InMemoryConfig.GetUsers()
                           .Find(u => u.SubjectId.Equals(sub));

                context.IssuedClaims.AddRange(user.Claims);
                return(Task.CompletedTask);
            }
Example #5
0
        public void ConfigureServices(IServiceCollection services)
        {
            services
            .AddIdentityServer()
            .AddInMemoryIdentityResources(InMemoryConfig.GetIdentityResources())
            .AddInMemoryApiResources(InMemoryConfig.GetApis())
            .AddInMemoryClients(InMemoryConfig.GetClients())
            .AddDeveloperSigningCredential();

#if DEBUG
            services
            .AddControllersWithViews(
                options =>
            {
                options.SuppressAsyncSuffixInActionNames = true;
            })
            .AddRazorRuntimeCompilation();
#else
            services
            .AddControllersWithViews();
#endif
        }