我不确定这是否是解决问题的好方法。但这是一种方式。我向我的路由服务询问“第一个身份服务”以在选项中设置权限。然后我添加了一个自定义 IntrospectionBackChannelHandler
app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions
{
Authority = $"http://{v.Address}:{v.Port}",
IntrospectionBackChannelHandler = new CustomIntrospectionBackChannelHandler(consulService)
由于我所有的身份服务器看起来都一样,但在不同的地址上,我真的不必费心再做一次权威的事情。
在自定义的 Introspect 中......我检查每个 introspect 并将其发送到“正确的”身份服务器。如果它不起作用,我尝试另一个身份服务器。
var qs = 等待 request.Content.ReadAsStringAsync(); var queryDic = QueryHelpers.ParseQuery(await request.Content.ReadAsStringAsync());
var token = queryDic["token"];
var client_id = queryDic["client_id"];
var client_secret = queryDic["client_secret"];
var iRequest = new IntrospectionRequest
{
ClientId = client_id,
ClientSecret = client_secret,
TokenTypeHint = "access_token",
Token = token
};
IntrospectionResponse result = null;
var svc = await _Consul.GetService(OrbitServices.IdentityServer);
result = await TrySendAsync(iRequest, svc);
if (!result.IsActive && result.IsError)
{
svc = await _Consul.GetService(OrbitServices.IdentityServer, true);
result = await TrySendAsync(iRequest, svc);
}
var message = new HttpResponseMessage(HttpStatusCode.OK)
{
Content = new StringContent(result.Raw, Encoding.UTF8, "application/json")
};
return message;