如果您还没有,请将这些 Nuget 包添加到您已经建立的 IdentityServer 应用程序/站点:
IdentityServer4.AccessTokenValidation
Microsoft.AspNetCore.Mvc
将另一个 Api 资源添加到您的资源列表中:
public static IEnumerable<ApiResource> GetApiResources()
{
return new List<ApiResource>
{
new ApiResource("api1", "My API"),
new ApiResource("api2", "IdentityServer API")
};
}
更新您的客户端配置以允许 api2:
public static IEnumerable<Client> GetClients()
{
return new List<Client>
{
new Client
{
ClientId = "mvc",
... omitted
AllowedScopes = new List<string>
{
IdentityServerConstants.StandardScopes.OpenId,
IdentityServerConstants.StandardScopes.Profile,
"api2"
}
}
};
}
在启动时IdentityServer的Configure方法中添加:
app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions
{
Authority = "http://localhost:5000",
RequireHttpsMetadata = false,
ApiName = "api2"
});