IdentityServer4 Config Log

Crime tools:VS2019 Postman

1. Create Asp.net Core Web Application

IdentityServer4  Config Log

 

2. Install IdentityServer4 by nuget package

IdentityServer4  Config Log

 

 

 

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

IdentityServer4  Config Log
  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

IdentityServer4  Config Log
  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 IdentityServer4  Config Log
        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)

IdentityServer4  Config Log

 

 IdentityServer4  Config Log

 

上一篇:【转】.NET Core开发日志——IHttpClientFactory


下一篇:Windows安全应急响应