服务器端: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();