var handler = new HttpClientHandler
{
    Proxy = new WebProxy("http://proxy.example:8080"),
    UseProxy = true
};
var http = new HttpClient(handler);
var documents = new HttpDocumentRetriever(http);

var configuration = await OpenIdConnectConfigurationRetriever.GetAsync(
    "https://issuer.example/.well-known/openid-configuration",
    documents,
    cancellationToken);

HttpDocumentRetriever 来自 Microsoft.IdentityModel.Protocols;OpenIdConnectConfigurationRetriever 来自其 OpenIdConnect 包。请让 HTTP 客户端在其工作期间保持存活。对于允许公共中间人的公共 discovery 与 JWKS URL,HTTP 代理列表可为 WebProxy 的 URL 提供候选。

查找会先获取 discovery,随后在存在时用同一个传入的 retriever 获取 jwks_uri。这些 URL 可能位于不同主机,代理必须同时放行两者。

如需代理认证,请在构造之前配置 WebProxy 的账户。它不是签发方的客户端密钥。

在长期运行的身份验证服务中,应把此 retriever 交给受支持的缓存与刷新机制,而不是为每个传入请求都下载配置。请让签发方、HTTPS 信任与令牌校验策略独立于此传输选择。

相关文章