gpt4 book ai didi

asp.net-core - 使用 ASPNET Core 2 从企业代理后面通过 Azure AD 进行身份验证

转载 作者:行者123 更新时间:2023-12-02 06:16:10 26 4
gpt4 key购买 nike

我有一个 ASPNET Core 2 应用程序,我正在尝试使用 OpenId 通过 Azure AD 进行身份验证。我只有在 ASPNET Core 2 模板中选择单一组织身份验证的样板代码,因此没有自定义代码。我关注了文章here.

由于代理,应用程序无法从 Azure AD 应用程序获取元数据。如果我将其粘贴到浏览器中,相同的 URL 会返回数据。

我得到的错误是:

HttpRequestException: Response status code does not indicate success: 407 (Proxy Authentication Required).

System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode() IOException: IDX10804: Unable to retrieve document from: 'https://login.microsoftonline.com/my-tenant-id/.well-known/openid-configuration'.

Microsoft.IdentityModel.Protocols.HttpDocumentRetriever+d__8.MoveNext()

我有另一个 ASPNET 4.5.2 应用程序,在代码中设置代理后,我可以使用与上面相同的 Azure AD 应用程序执行身份验证,如下所示:

System.Net.HttpWebRequest.DefaultWebProxy = new WebProxy
{
Address = new Uri("http://my-company-proxy:8080"),
Credentials = new NetworkCredential
{
UserName = "proxyusername",
Password = "proxypassword"
}
};

所以本质上我的问题是通过 ASPNET Core 2 中的代理身份验证。

我尝试过 Microsoft.AspNetCore.Proxy 包。它几乎坏了,对我不起作用。我还尝试在 machine.config 中添加代理条目(实际上 4.5.2 应用程序不需要),但这也不起作用。我相信通过公司代理应该非常简单,但到目前为止看起来还不是这样。

最佳答案

Tratcher 的评论为我指明了正确的方向,并且我成功了,但为了帮助每个人,以下是您需要执行的操作:

  builder.AddOpenIdConnect(options => options.BackchannelHttpHandler = new HttpClientHandler
{
UseProxy = true,
Proxy = new WebProxy
{
Credentials = new NetworkCredential
{
UserName = "myusername",
Password = "mypassword"
},
Address = new Uri("http://url:port")
}
});

关于asp.net-core - 使用 ASPNET Core 2 从企业代理后面通过 Azure AD 进行身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49619519/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com