其他分享
首页 > 其他分享> > IdentityServer4 Config Log

IdentityServer4 Config Log

作者:互联网

Crime tools:VS2019 Postman

1. Create Asp.net Core Web Application

 

2. Install IdentityServer4 by nuget package

 

 

 

 3. Create a class used to simulate clients/users/resources/scopes

  public void ConfigureServices(IServiceCollection services)
        {
            services.AddIdentityServer()
                .AddDeveloperSigningCredential()
                .AddInMemoryApiResources(IdentityServerConfig.GetResources())
                .AddInMemoryApiScopes(IdentityServerConfig.GetScopes())
                .AddInMemoryClients(IdentityServerConfig.GetClients())
                .AddTestUsers(IdentityServerConfig.GetTests());


            services.AddControllers();
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo { Title = "IdentityServer4_Demo", Version = "v1" });
            });
        }
ConfigureServices

 

4. Regiser IdentityServer4 in Startup.cs file

  public void ConfigureServices(IServiceCollection services)
        {
            services.AddIdentityServer()
                .AddInMemoryApiResources(IdentityServerConfig.GetResources())
                .AddInMemoryApiScopes(IdentityServerConfig.GetScopes())
                .AddInMemoryClients(IdentityServerConfig.GetClients())
                .AddTestUsers(IdentityServerConfig.GetTests());

            services.AddControllers();
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo { Title = "IdentityServer4_Demo", Version = "v1" });
            });
        }
ConfigureServices
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseSwagger();
                app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "IdentityServer4_Demo v1"));
            }
            app.UseIdentityServer();
            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
Configure

 

5. Test with postman (password/client_credential)

 

 

 

标签:Log,app,v1,services,IdentityServerConfig,Config,IdentityServer4,ConfigureService
来源: https://www.cnblogs.com/kevin-xk/p/14781888.html