【发布时间】:2017-06-29 19:30:42
【问题描述】:
我正在尝试使用 docker 配置 IdentityServer4,但无法使其正常工作。首先,我使用了身份服务器文档的客户端凭据示例:Protecting an API using Client Credentials
身份服务器
托管在端口 5000
WebApi
托管在端口 5001
在我的 WebApi 的Startup.cs 文件的Configure 方法中,我做了以下操作(问题可能就在这里):
app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions
{
Authority = "http://web:5000",
RequireHttpsMetadata = false,
ApiName = "api1"
});
客户
和客户
// Everything is fine here...
var disco = await DiscoveryClient.GetAsync("http://localhost:5000");
var tokenClient = new TokenClient(disco.TokenEndpoint, "client", "secret");
var tokenResponse = await tokenClient.RequestClientCredentialsAsync("api");
// This does not work
var client = new HttpClient();
client.SetBearerToken(tokenResponse.AccessToken);
var response = await client.GetAsync("http://localhost:5001/identity");
问题可能出在我的 WebApi 上:
1) 如果我将权限设置为 localhost:5000,我会收到内部服务器错误:“无法从以下位置获取配置:'http://localhost:5000/.well-known/openid-configuration'”这是有道理的,因为 localhost:5000 在此容器中是未知的
2) 如果我将权限设置为http://web:5000,则会收到授权错误:“颁发者验证失败。颁发者:'http://localhost:5000'。不匹配:validationParameters.ValidIssuer:'http://web:5000'或validationParameters.ValidIssuers “这也有道理,但我不知道是否可以更改权限名称?我还尝试在 IdentityServer 项目中设置IssuerUri,但没有帮助
【问题讨论】:
-
如果您有兴趣,我在这里问过类似的问题。 stackoverflow.com/questions/53468074/… +1 表示您问题的第二点 - 我整天都在为此苦苦挣扎。
标签: c# docker .net-core identityserver4