IdentityServer

服务器端:http://localhost:5000

  新增config.cs
  public static IEnumerable<ApiResource> GetResource()
    {
        return new List<ApiResource>
        {
            new ApiResource("api","My Api")
        };
    }
    public static IEnumerable<Client> GetClients()
    {
        return new List<Client>
        {
            new Client
            {
                ClientId="client",
                AllowedGrantTypes=GrantTypes.ClientCredentials,
                ClientSecrets = {
                    new Secret("secret".Sha256())
                },
                AllowedScopes={ "api"}
            }
        };
    }
  Startup类:
   public void ConfigureServices(IServiceCollection services)
    {
        services.AddIdentityServer()
            .AddDeveloperSigningCredential()
            .AddInMemoryApiResources(Config.GetResource())
            .AddInMemoryClients(Config.GetClients());
        services.AddMvc();
    }
方法Configure 添加app.UseIdentityServer();

客户端:http://localhost:5001

 startup类
  public void ConfigureServices(IServiceCollection services)
    {
        services.AddAuthentication("Bearer")
            .AddIdentityServerAuthentication(options=> {
                options.Authority = "http://localhost:5000";
                options.RequireHttpsMetadata = false;
                options.ApiName = "api";
            });
        services.AddMvc();
    }
方法Configure添加 app.UseIdentityServer();
posted @ 2020-12-17 17:34  泽哥的学习笔记  阅读(133)  评论(0编辑  收藏  举报