Example #1
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllersWithViews().AddJsonOptions(o => o.JsonSerializerOptions.WriteIndented = true);


            services.AddCors(options =>
            {
                // this defines a CORS policy called "default"
                options.AddPolicy("default", policy =>
                {
                    policy.WithOrigins("http://localhost:8100")
                    .AllowAnyHeader()
                    .AllowAnyMethod();
                });
            });

            // Modify for https
            // HTTPS
            // const issuer = "https://identityserver/";
            // HTTP
            var issuer = "http://identityserver/";

            // HTTP
            var builder = services.AddIdentityServer(o => o.IssuerUri = issuer)
                          .AddInMemoryIdentityResources(Config.Ids)
                          .AddInMemoryApiResources(Config.Apis)
                          .AddInMemoryClients(Config.Clients)
                          .AddTestUsers(TestUsers.Users());


            builder.AddDeveloperSigningCredential();

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

            //        options.ClientId = "<insert here>";
            //        options.ClientSecret = "<insert here>";
            //    })
            //    .AddOpenIdConnect("oidc", "Demo IdentityServer", options =>
            //    {
            //        options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme;
            //        options.SignOutScheme = IdentityServerConstants.SignoutScheme;
            //        options.SaveTokens = true;

            //        options.Authority = "https://demo.identityserver.io/";
            //        options.ClientId = "native.code";
            //        options.ClientSecret = "secret";
            //        options.ResponseType = "code";

            //        options.TokenValidationParameters = new TokenValidationParameters
            //        {
            //            NameClaimType = "name",
            //            RoleClaimType = "role"
            //        };
            //    });
        }
        public AccountController(
            IIdentityServerInteractionService interaction,
            IClientStore clientStore,
            IAuthenticationSchemeProvider schemeProvider,
            IEventService events,
            TestUserStore users = null)
        {
            // if the TestUserStore is not in DI, then we'll just use the global users collection
            // this is where you would plug in your own custom identity management library (e.g. ASP.NET Identity)
            _users = users ?? new TestUserStore(TestUsers.Users());

            _interaction    = interaction;
            _clientStore    = clientStore;
            _schemeProvider = schemeProvider;
            _events         = events;
        }