Exemplo n.º 1
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();

            var connectionString   = @"server=(localdb)\mssqllocaldb;database=IdentityServer4.QuickStart;trusted_connection=yes";
            var migrationsAssembly = typeof(Startup).GetTypeInfo().Assembly.GetName().Name;

            // configure identity server with in-memory users, but EF stores for clients and scopes
            services.AddIdentityServer()
            .AddTemporarySigningCredential()
            .AddTestUsers(Config.GetUsers())
            .AddConfigurationStore(builder =>
                                   builder.UseSqlServer(connectionString, options =>
                                                        options.MigrationsAssembly(migrationsAssembly)))
            .AddOperationalStore(builder =>
                                 builder.UseSqlServer(connectionString, options =>
                                                      options.MigrationsAssembly(migrationsAssembly)));
        }
Exemplo n.º 2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddIdentityServer()
            .AddInMemoryIdentityResources(Config.GetIdentityResources())
            .AddInMemoryApiResources(Config.GetApiResources())
            .AddInMemoryClients(Config.GetClients())
            .AddTestUsers(Config.GetUsers())
            .AddProfileService <AdditionalClaimsProfileService>()
            .AddDeveloperSigningCredential();

            // use in memory for testing.
            services
            .AddDbContext <IdentityServerContext>(opt => opt.UseMySql(Configuration.GetConnectionString("MyConnectionString")))    //"Server=localhost;database=uow;uid=root;pwd=root1234;"))
            .AddUnitOfWork <IdentityServerContext>()
            .AddCustomRepository <User, UserRepository>();


            services.AddMvc();
        }
Exemplo n.º 3
0
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();

            // 使用内存存储,密钥,客户端和资源来配置身份服务器。
            services.AddIdentityServer()
            .AddDeveloperSigningCredential()
            .AddInMemoryIdentityResources(Config.GetIdentityResources())
            .AddInMemoryApiResources(Config.GetApiResources()) //添加api资源
            .AddInMemoryClients(Config.GetClients())           //添加客户端
            .AddTestUsers(Config.GetUsers());                  //添加测试用户

            services.AddAuthentication()
            .AddQQ(qq =>
            {
                qq.AppId  = "101543795";
                qq.AppKey = "3dafebb5bd15c6cb4fe9144758898645";
            });
        }
Exemplo n.º 4
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();


            //services.AddAuthentication()
            //    .AddMicrosoftAccount(MicrosoftAccountDefaults.AuthenticationScheme, options =>
            //    {
            //        options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme;
            //        options.ClientId = "33f1f15d-93d5-4749-9b0e-24fc7c0bf56e";
            //        options.ClientSecret = "wttGKYI05[vppzBAG913#?_";
            //    });
            // configure identity server with in-memory stores, keys, clients and scopes
            services.AddIdentityServer()
            .AddDeveloperSigningCredential()
            .AddInMemoryIdentityResources(Config.GetIdentityResources())
            .AddInMemoryApiResources(Config.GetApiResources())
            .AddInMemoryClients(Config.GetClients())
            .AddTestUsers(Config.GetUsers());
        }
Exemplo n.º 5
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();

            // configure identity server with in-memory stores, keys, clients and scopes

            services.AddIdentityServer()
            .AddDeveloperSigningCredential()
            .AddInMemoryIdentityResources(Config.GetIdentityResources())
            .AddInMemoryApiResources(Config.GetApiResources())
            .AddInMemoryClients(Config.GetClients())
            .AddTestUsers(Config.GetUsers());

            services.AddAuthentication()
            .AddQQ(qqOptions =>
            {
                qqOptions.AppId  = "这里配置";
                qqOptions.AppKey = "这里配置";
            });
        }
Exemplo n.º 6
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();

            // configure identity server with in-memory stores, keys, clients and scopes
            services.AddIdentityServer()
            .AddDeveloperSigningCredential()
            .AddInMemoryIdentityResources(Config.GetIdentityResources())
            .AddInMemoryApiResources(Config.GetApiResources())
            .AddInMemoryClients(Config.GetClients())
            .AddTestUsers(Config.GetUsers());


            services.AddAuthentication()     //options => {
            //options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
            //options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
            //})

            .AddCookie(CookieAuthenticationDefaults.AuthenticationScheme)
            .AddGoogle("Google", options =>
            {
                options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme;
                options.ClientId     = "172986759996-f031j0mlqh8k9qgumm3h602cm5rt0595.apps.googleusercontent.com";
                options.ClientSecret = "R4Rd84vx1Gab7cJo-bJhXl6v";
            })
            .AddOpenIdConnect(OpenIdConnectDefaults.AuthenticationScheme, "Azure Portal", options =>
            {
                options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme;
                options.ClientId     = "415ee7f3-0c53-4c58-9579-3cf54c1fd63e";
                // options.ClientSecret = "7KyCzTicUzgDuAL5wf/JGdM23bSEnCyBuwAwK6IxN3w=";
                options.Authority    = $"https://login.microsoftonline.com/common";
                options.ResponseType = OpenIdConnectResponseType.IdToken;

                options.TokenValidationParameters = new TokenValidationParameters
                {
                    ValidIssuer   = "https://sts.windows.net/8d327499-ca18-4d3b-b150-24dfd1cbf5f5/",
                    NameClaimType = "name",
                    RoleClaimType = "role"
                };
            });
        }
Exemplo n.º 7
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();

            // configure identity server with in-memory stores, keys, clients and scopes
            services.AddIdentityServer()
            .AddDeveloperSigningCredential()
            .AddInMemoryIdentityResources(Config.GetIdentityResources())
            .AddInMemoryApiResources(Config.GetApiResources())
            .AddInMemoryClients(Config.GetClients())
            .AddTestUsers(Config.GetUsers());

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

                options.ClientId     = "434483408261-55tc8n0cs4ff1fe21ea8df2o443v2iuc.apps.googleusercontent.com";
                options.ClientSecret = "3gcoTrEDPPJ0ukn_aYYT6PWo";
            });
        }
Exemplo n.º 8
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddCors(options =>
            {
                options.AddPolicy("CorsPolicy",
                                  builder => builder.AllowAnyOrigin()
                                  .AllowAnyMethod()
                                  .AllowAnyHeader()
                                  .AllowCredentials());
            });

            services.AddMvc();

            // configure identity server with in-memory stores, keys, clients and scopes
            services.AddIdentityServer()
            .AddTemporarySigningCredential()
            .AddInMemoryIdentityResources(Config.GetIdentityResources())
            .AddInMemoryApiResources(Config.GetApiResources())
            .AddInMemoryClients(Config.GetClients())
            .AddTestUsers(Config.GetUsers());
        }
Exemplo n.º 9
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();

            // configure identity server with in-memory stores, keys, clients and scopes
            services.AddIdentityServer()
            .AddDeveloperSigningCredential()
            .AddInMemoryIdentityResources(Config.GetIdentityResources())
            .AddInMemoryApiResources(Config.GetApiResources())
            .AddInMemoryClients(Config.GetClients())
            .AddTestUsers(Config.GetUsers());

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

                options.ClientId     = "1005450161824-hqg5jq2qnplaskfnjcor4erfb5m8g0rs.apps.googleusercontent.com";
                options.ClientSecret = "GPj_fCos-5jC1dhqNL3yCZjE";
            });
        }
Exemplo n.º 10
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();

            // configure identity server with in-memory stores, keys, clients and scopes
            services.AddIdentityServer()
            .AddDeveloperSigningCredential()
            .AddInMemoryIdentityResources(Config.GetIdentityResources())
            .AddInMemoryApiResources(Config.GetApiResources())
            .AddInMemoryClients(Config.GetClients())
            .AddTestUsers(Config.GetUsers());

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

                options.ClientId     = "113871300477-jiaci39qj3jcv1rmt9in6kpc1m8ml769.apps.googleusercontent.com";
                options.ClientSecret = "rYrcx3ekWiqR6d35FqUQnMP2";
            });
        }
Exemplo n.º 11
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();

            // configure identity server with in-memory stores, keys, clients and scopes
            services.AddIdentityServer()
            .AddDeveloperSigningCredential()
            .AddInMemoryIdentityResources(Config.GetIdentityResources())
            .AddInMemoryApiResources(Config.GetApiResources())
            .AddInMemoryClients(Config.GetClients())
            .AddTestUsers(Config.GetUsers())
            //.AddWsFederation()
            //.AddInMemoryRelyingParties(Config.GetRelyingParties())
            ;


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

                options.ClientId     = "434483408261-55tc8n0cs4ff1fe21ea8df2o443v2iuc.apps.googleusercontent.com";
                options.ClientSecret = "3gcoTrEDPPJ0ukn_aYYT6PWo";
            })
            .AddOpenIdConnect("oidc", "OpenID Connect", options =>
            {
                options.SignInScheme  = IdentityServerConstants.ExternalCookieAuthenticationScheme;
                options.SignOutScheme = IdentityServerConstants.SignoutScheme;

                options.Authority = "https://demo.identityserver.io/";
                options.ClientId  = "implicit";

                options.TokenValidationParameters = new TokenValidationParameters
                {
                    NameClaimType = "name",
                    RoleClaimType = "role"
                };
            });
        }
Exemplo n.º 12
0
        public void ConfigureServices(IServiceCollection services)
        {
            //services.AddCors(options =>
            //{
            //    options.AddPolicy("AllowSpecificOrigin",
            //        builder => builder.WithOrigins("http://example.com").AllowAnyHeader());
            //});

            services.AddMvc(options =>
            {
                options.Filters.Add(new UrlReferrerFilter()); // an instance
            });

            // configure identity server with in-memory stores, keys, clients and scopes
            services.AddIdentityServer()
            .AddTemporarySigningCredential()
            .AddInMemoryIdentityResources(Config.GetIdentityResources())
            .AddInMemoryApiResources(Config.GetApiResources())
            .AddInMemoryClients(Config.GetClients())
            .AddTestUsers(Config.GetUsers())
            .AddProfileService <CustomProfileService>();
        }
Exemplo n.º 13
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();

            // configure identity server with in-memory stores, keys, clients and scopes
            services.AddIdentityServer()
            .AddDeveloperSigningCredential()
            .AddInMemoryIdentityResources(Config.GetIdentityResources())
            .AddInMemoryApiResources(Config.GetApiResources())
            .AddInMemoryClients(Config.GetClients())
            .AddTestUsers(Config.GetUsers());

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

                // register your IdentityServer with Google at https://console.developers.google.com
                // enable the Google+ API
                // set the redirect URI to http://localhost:port/signin-google
                options.ClientId     = "copy client ID from Google here";
                options.ClientSecret = "copy client secret from Google here";
            })
            .AddOpenIdConnect("oidc", "OpenID Connect", options =>
            {
                options.SignInScheme  = IdentityServerConstants.ExternalCookieAuthenticationScheme;
                options.SignOutScheme = IdentityServerConstants.SignoutScheme;

                options.Authority = "https://demo.identityserver.io/";
                options.ClientId  = "implicit";

                options.TokenValidationParameters = new TokenValidationParameters
                {
                    NameClaimType = "name",
                    RoleClaimType = "role"
                };
            });
        }
Exemplo n.º 14
0
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddCors(options =>
            {
                // this defines a CORS policy called "default"
                options.AddPolicy("default", policy =>
                {
                    policy.WithOrigins("http://*****:*****@"server=(localdb)\mssqllocaldb;database=IdentityServer4.QuickStart;trusted_connection=yes";
            var migrationsAssembly = typeof(Startup).GetTypeInfo().Assembly.GetName().Name;

            // configure identity server with in-memory stores, keys, clients and scopes
            //services.AddIdentityServer()
            //    .AddTemporarySigningCredential()
            //    .AddInMemoryApiResources(Config.GetApiResources())
            //    .AddInMemoryClients(Config.GetClients())
            //    .AddInMemoryIdentityResources(Config.GetIdentityResources())
            //    .AddTestUsers(Config.GetUsers());

            // configure identity server with in-memory users, but EF stores for clients and scopes
            services.AddIdentityServer()
            .AddTemporarySigningCredential()
            .AddTestUsers(Config.GetUsers())
            .AddConfigurationStore(builder =>
                                   builder.UseSqlServer(connectionString, options =>
                                                        options.MigrationsAssembly(migrationsAssembly)))
            .AddOperationalStore(builder =>
                                 builder.UseSqlServer(connectionString, options =>
                                                      options.MigrationsAssembly(migrationsAssembly)));
        }
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();

            var connectionString =
                @"server=(localdb)\mssqllocaldb;database=IdentityServer4.Quickstart;trusted_connection=yes";
            var migrationsAssembly = typeof(Startup).GetTypeInfo().Assembly.GetName().Name;

            // configure identity server with in-memory stores, keys, clients and scopes
            services.AddIdentityServer()
            .AddTemporarySigningCredential()
            //the following were only needed for initial development
            //.AddInMemoryIdentityResources(Config.GetIdentityResources())
            //.AddInMemoryApiResources(Config.GetApiResources())
            //.AddInMemoryClients(Config.GetClients())
            .AddTestUsers(Config.GetUsers())
            .AddConfigurationStore(builder =>
                                   builder.UseSqlServer(connectionString, options =>
                                                        options.MigrationsAssembly(migrationsAssembly)))
            .AddOperationalStore(builder =>
                                 builder.UseSqlServer(connectionString, options =>
                                                      options.MigrationsAssembly(migrationsAssembly)));
        }
Exemplo n.º 16
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddCors();
            services.AddMvc();

            // configure identity server with in-memory stores, keys, clients and scopes
            services.AddIdentityServer()
            .AddDeveloperSigningCredential()
            .AddInMemoryIdentityResources(Config.GetIdentityResources())
            .AddInMemoryApiResources(Config.GetApiResources())
            .AddInMemoryClients(Config.GetClients())
            .AddTestUsers(Config.GetUsers());


            services.AddAuthentication()
            .AddWsFederation(options =>
            {
                options.Wtrealm          = "https://priveravardgivaremikael.vgregion.se/";
                options.MetadataAddress  = "https://win-i5vs66s3gnb.priveramikael.com/federationmetadata/2007-06/federationmetadata.xml";
                options.UseTokenLifetime = true;
                //options.CallbackPath = new PathString("/ExternalLoginCallback");
            });
        }
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();

            /*var connectionString = @"server=(localdb)\mssqllocaldb;database=IdentityServer4.QuickStart.EntityFramework;trusted_connection=yes";
             * var migrationsAssembly = typeof(Startup).GetTypeInfo().Assembly.GetName().Name;*/

            // configure identity server with in-memory users, but EF stores for clients and scopes
            services.AddIdentityServer()
            .AddTemporarySigningCredential()
            .AddTestUsers(Config.GetUsers())
            // support for Google Cloud Datastore
            .AddConfigurationStore(option =>
            {
                option.ProjectId           = "[YOUR-PROJECT-ID]";
                option.Namespace           = "[YOUR-NAMESPACE]";
                option.CredentialsFilePath = ".[YOUR-PROJECT-SERVICE-KEY-FILEPATH]";
            })
            // this adds the operational data from DB (codes, tokens, consents)
            .AddOperationalStore(option =>
            {
                option.ProjectId           = "[YOUR-PROJECT-ID]";
                option.Namespace           = "[YOUR-NAMESPACE]";
                option.CredentialsFilePath = ".[YOUR-PROJECT-SERVICE-KEY-FILEPATH]";

                // this enables automatic token cleanup. this is optional.
                option.EnableTokenCleanup   = true;
                option.TokenCleanupInterval = 5 * 60;
            });

            /*.AddConfigurationStore(builder =>
             *  builder.UseSqlServer(connectionString, options =>
             *      options.MigrationsAssembly(migrationsAssembly)))
             * .AddOperationalStore(builder =>
             *  builder.UseSqlServer(connectionString, options =>
             *      options.MigrationsAssembly(migrationsAssembly)));*/
        }
Exemplo n.º 18
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddIdentityServer()
            .AddDeveloperSigningCredential()
            .AddInMemoryApiResources(Config.GetApiResources())
            .AddInMemoryClients(Config.GetClients())
            .AddInMemoryIdentityResources(Config.GetIdentityResources())
            .AddTestUsers(Config.GetUsers());

            //services.AddAuthentication()
            //    .AddQQ(a =>
            //    {
            //        a.AppId = "";
            //        a.AppKey = "";
            //    });

            //使用OpenID Connect进行外部登录集成
            //services.AddAuthentication()
            //    .AddOpenIdConnect("oidc", "OpenID Connect", a =>
            //      {
            //          a.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme;
            //          a.SignOutScheme = IdentityServerConstants.SignoutScheme;

            //          a.Authority = "https://demo.identityserver.io/";
            //          a.ClientId = "implicit";

            //          a.TokenValidationParameters = new Microsoft.IdentityModel.Tokens.TokenValidationParameters
            //          {
            //              NameClaimType = "name",
            //              RoleClaimType = "role"
            //          };

            //      });


            services.AddMvc();
        }
Exemplo n.º 19
0
        private static async Task InitUsers(IServiceScope scope)
        {
            var context     = scope.ServiceProvider.GetRequiredService <ApplicationDbContext>();
            var userManager = scope.ServiceProvider.GetRequiredService <UserManager <ApplicationUser> >();

            if (!context.Users.Any())
            {
                Console.WriteLine("Clients being populated");
                foreach (var u in Config.GetUsers().ToList())
                {
                    var user = new ApplicationUser
                    {
                        UserName = u.Username,
                        Email    = u.Username
                    };

                    await userManager.CreateAsync(user, u.Password);
                }
            }
            else
            {
                Console.WriteLine("Clients already populated");
            }
        }
Exemplo n.º 20
0
// Copyright (c) Brock Allen & Dominick Baier. All rights reserved.
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.

using IdentityServer4;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.IdentityModel.Tokens;
using System.IO;
using System.Security.Cryptography.X509Certificates;

namespace QuickstartIdentityServer
{
    public class Startup
    {
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();
			services.AddIdentityServer()
				//.AddDeveloperSigningCredential()
				.AddSigningCredential(Certificate.GetCertificate())
				.AddInMemoryIdentityResources(Config.GetIdentityResources())
				.AddInMemoryApiResources(Config.GetApiResources())
				.AddInMemoryPersistedGrants()
				.AddInMemoryClients(Config.GetClients())
				.AddTestUsers(Config.GetUsers());

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

					// register your IdentityServer with Google at https://console.developers.google.com
					// enable the Google+ API
					// set the redirect URI to http://localhost:port/signin-google
					options.ClientId = "copy client ID from Google here";
					options.ClientSecret = "copy client secret from Google here";
				})
				.AddOpenIdConnect("oidc", "OpenID Connect", options =>
				{
					options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme;
					options.SignOutScheme = IdentityServerConstants.SignoutScheme;

					options.Authority = "https://identity.buyingagentapp.com/";
					options.ClientId = "implicit";

					options.TokenValidationParameters = new TokenValidationParameters
					{
						NameClaimType = "name",
						RoleClaimType = "role"
					};
				});
		}

        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
			else
			{
				app.UseExceptionHandler();
			}

			app.UseIdentityServer();

            app.UseStaticFiles();
            app.UseMvcWithDefaultRoute();
        }
    }
}
Exemplo n.º 21
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDataProtection(options => options.ApplicationDiscriminator = "00000").SetApplicationName("00000");

            services.AddMvc();

            // configure identity server with in-memory stores, keys, clients and scopes
            services.AddIdentityServer(Option =>
            {
                Option.PublicOrigin = "http://localhost:54660/IdentityServer/";
                Option.IssuerUri    = "http://localhost:54660/IdentityServer/";
            })
            .AddDeveloperSigningCredential()
            .AddInMemoryIdentityResources(Config.GetIdentityResources())
            .AddInMemoryApiResources(Config.GetApiResources())
            .AddInMemoryClients(Config.GetClients())
            .AddTestUsers(Config.GetUsers());

            //CspOptions = new CspOptions
            //{
            //    Enabled = false,
            //}
            //JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();
            //services.AddAuthentication(options =>
            //{
            //    options.DefaultScheme = "Cookies";
            //    options.DefaultChallengeScheme = "oidc";
            //}).AddCookie("Cookies")
            //.AddOpenIdConnect("oidc", options =>
            //{
            //    options.SignInScheme = "Cookies";

            //    options.Authority = "http://localhost:54660/IdentityServer";
            //    options.RequireHttpsMetadata = false;

            //    options.ClientId = "mvc";
            //    options.ClientSecret = "secret";
            //    options.ResponseType = "code id_token";

            //    options.SaveTokens = true;
            //    options.GetClaimsFromUserInfoEndpoint = true;

            //    options.Scope.Add("api1");
            //    options.Scope.Add("offline_access");
            //});
            //services.AddAuthentication(options =>
            //{
            //    options.DefaultScheme = "ZfsoftCookies";
            //    options.DefaultChallengeScheme = "oidc";
            //    //options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
            //})
            //    .AddCookie("ZfsoftCookies", options =>
            //    {
            //        options.ExpireTimeSpan = TimeSpan.FromMinutes(30);
            //        options.SlidingExpiration = true;
            //    })
            //    .AddOpenIdConnect("oidc", options =>
            //    {
            //        options.SignInScheme = "ZfsoftCookies";

            //        options.Authority = "http://localhost:50876/";
            //        options.RequireHttpsMetadata = false;

            //        options.ClientId = "mvc";
            //        options.ClientSecret = "secret";
            //        options.ResponseType = "code id_token";

            //        options.SaveTokens = true;
            //        options.GetClaimsFromUserInfoEndpoint = true;

            //        options.Scope.Add("api1");
            //        //options.Scope.Add("role");
            //        options.Scope.Add("offline_access");
            //    });
            //services.AddAuthentication()
            //.AddGoogle("Google", options =>
            //{
            //    options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme;

            //    options.ClientId = "434483408261-55tc8n0cs4ff1fe21ea8df2o443v2iuc.apps.googleusercontent.com";
            //    options.ClientSecret = "3gcoTrEDPPJ0ukn_aYYT6PWo";
            //})
            //.AddOpenIdConnect("oidc", "OpenID Connect", options =>
            //{
            //    options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme;
            //    options.SignOutScheme = IdentityServerConstants.SignoutScheme;

            //    options.Authority = "https://demo.identityserver.io/";
            //    options.ClientId = "implicit";

            //    options.TokenValidationParameters = new TokenValidationParameters
            //    {
            //        NameClaimType = "name",
            //        RoleClaimType = "role"
            //    };
            //});
        }
Exemplo n.º 22
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();

            var migrationsAssembly = typeof(Startup).GetTypeInfo().Assembly.GetName().Name;

            // configure identity server with in-memory stores, keys, clients and scopes
            services.AddIdentityServer()
            .AddDeveloperSigningCredential()
            .AddTestUsers(Config.GetUsers())
            // this adds the config data from DB (clients, resources)
            // Using Mongo DB
            .AddConfigurationStore(option =>
            {
                option.ConnectionString = "mongodb://192.168.1.125:27017";
                option.Database         = "IdentityServer";
            })
            // this adds the operational data from DB (codes, tokens, consents)
            .AddOperationalStore(option =>
            {
                option.ConnectionString = "mongodb://192.168.1.125:27017";
                option.Database         = "IdentityServer";

                // this enables automatic token cleanup. this is optional.
                option.EnableTokenCleanup   = true;
                option.TokenCleanupInterval = 5 * 60;
            });

            /** Using EF
             * .AddConfigurationStore(options =>
             * {
             *  options.ConfigureDbContext = builder =>
             *      builder.UseSqlServer(connectionString,
             *          sql => sql.MigrationsAssembly(migrationsAssembly));
             * })
             * // this adds the operational data from DB (codes, tokens, consents)
             * .AddOperationalStore(options =>
             * {
             *  options.ConfigureDbContext = builder =>
             *      builder.UseSqlServer(connectionString,
             *          sql => sql.MigrationsAssembly(migrationsAssembly));
             *
             *  // this enables automatic token cleanup. this is optional.
             *  options.EnableTokenCleanup = true;
             *  options.TokenCleanupInterval = 30;
             * });
             */

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

                options.ClientId     = "434483408261-55tc8n0cs4ff1fe21ea8df2o443v2iuc.apps.googleusercontent.com";
                options.ClientSecret = "3gcoTrEDPPJ0ukn_aYYT6PWo";
            })
            .AddOpenIdConnect("oidc", "OpenID Connect", options =>
            {
                options.SignInScheme  = IdentityServerConstants.ExternalCookieAuthenticationScheme;
                options.SignOutScheme = IdentityServerConstants.SignoutScheme;

                options.Authority = "https://demo.identityserver.io/";
                options.ClientId  = "implicit";

                options.TokenValidationParameters = new TokenValidationParameters
                {
                    NameClaimType = "name",
                    RoleClaimType = "role"
                };
            });
        }