gpt4 book ai didi

.net - Postman 客户端凭据流与 Azure AD 保护资源

转载 作者:行者123 更新时间:2023-12-04 15:08:26 24 4
gpt4 key购买 nike

我目前正在使用这个例子:

https://docs.microsoft.com/en-us/azure/active-directory/active-directory-authentication-scenarios#daemon-or-server-application-to-web-api

在 Azure AD 中使用 OAuth 检查客户端凭据流。从理论上讲,该示例可以正常工作。客户端应用程序成功与服务器应用程序通信,首先从 Azure AD token url 获取 OAuth token 。没有问题。但是,我正在尝试使用 Postman 检查客户端凭据流,但无法使其正常工作。

在 Postman 中,我应该提供一个 访问 token 网址 , 客户 ID 和一个 客户端 secret , 授予类型 设置为 客户凭证 .使用与 https://github.com/Azure-Samples/active-directory-dotnet-daemon 中 Microsoft 示例提供的示例中相同的参数, 我得到一个 401 尝试访问 Web 服务时的响应。我认为主要原因是因为在 Postman 中,我无法输入 资源我想访问,所以收到的 token 没有“链接”到任何资源,这就是 Web 服务器中授权失败的原因?这可能是原因吗?如果这是原因,那么我应该在服务器中做什么,因为不知何故, postman 的要求似乎应该是客户端凭据流中有效的要求(我的意思是,不应该给出 资源 ,根据 OAuth2 客户端凭据流,对吗?

这是从微软示例下载的示例中Starup类的代码

    // For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
public void ConfigureAuth(IAppBuilder app)
{
app.UseWindowsAzureActiveDirectoryBearerAuthentication(
new WindowsAzureActiveDirectoryBearerAuthenticationOptions
{
Audience = ConfigurationManager.AppSettings["ida:Audience"],
Tenant = ConfigurationManager.AppSettings["ida:Tenant"]
});
}

ConfigurationManager.AppSettings["ida:Tenant"] 是我的 Azure AD 帐篷,而
ConfigurationManager.AppSettings["ida:Audience"] 是我需要访问的 protected 资源。这两个值都是必需的,如果我不提供 Audience,我会在 .NET Web API 初始化中收到错误消息。

最佳答案

I think the main reason is because in Postman, I can not type the resource I want to access, so the received token is not "linked" to any resource and that is why the authorization fails in the web server? Could this be the reason?


你是对的。通过 获取访问 token 客户端凭据流 ,我们需要提供 资源在请求中。
无法输入资源是什么意思?资源参数是我们可以将其包含在正文中的参数,这里有一张图供您引用:
enter image description here
并确保 resrouce 的值等于 观众用于保护资源的配置。

关于.net - Postman 客户端凭据流与 Azure AD 保护资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40641616/

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