【发布时间】:2017-03-31 05:04:09
【问题描述】:
我目前正在使用这个例子:
在 Azure AD 中使用 OAuth 检查客户端凭据流。从理论上讲,该示例可以正常工作。客户端 App 成功与服务器 App 通信,首先从 Azure AD 令牌 url 获取 OAuth 令牌。那里没有问题。但是,我正在尝试使用 Postman 检查客户端凭据流,但我无法使其正常工作。
在 Postman 中,我应该提供 Access Token Url、Client ID 和 Client Secret、Grant Type 设置为 客户凭据。使用与https://github.com/Azure-Samples/active-directory-dotnet-daemon 中 Microsoft 示例提供的示例相同的参数,我在尝试访问 Web 服务时收到 401 响应。我认为主要原因是因为在 Postman 中,我无法输入我想要访问的 resource,因此收到的令牌没有“链接”到任何资源,这就是网络授权失败的原因服务器?这可能是原因吗?如果这是原因,那么我应该在服务器上做什么,因为不知何故,邮递员的要求似乎应该是客户端凭据流中有效的要求(我的意思是,不应该提供 resource ,根据 OAuth2 客户端凭据流程,对吗?
这是从 Microsoft 示例下载的示例中 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"] 是我需要访问的受保护资源。这两个值都是必需的,如果我不提供 Audience,我会在 .NET Web API 初始化中收到错误。
【问题讨论】:
-
有一个跟踪此问题的 GitHub 问题:github.com/postmanlabs/postman-app-support/issues/4391
标签: .net authentication asp.net-web-api oauth-2.0 azure-active-directory