gpt4 book ai didi

azure - 无法使用不记名 token 访问 AAD 安全 Web API

转载 作者:行者123 更新时间:2023-12-01 09:50:43 24 4
gpt4 key购买 nike

我有一个使用 Azure AD (AAD) 保护的 API 应用。我还有一个用于消费应用程序的 AAD 应用程序,并且在消费应用程序中我设置了访问 API 应用程序的权限。

我能够获取 token ,但是当我使用 token 时,API 应用程序似乎不会查看授权 header 。它尝试通过网络浏览器让我登录。

我的请求如下所示:

    GET /api/ticketing/issueTopics HTTP/1.1
Host: <removed>
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGc<rest is removed>
Cache-Control: no-cache

This is what my Fiddler looks like.

我在 Postman 中得到的结果是一些 MS 重定向页面:

<html>
<head>
<title>Working...</title>
</head>
<body>
<form method="POST" name="hiddenform" action="<removed>/.auth/login/aad/callback">
<input type="hidden" name="id_token" value="<bearer token removed>" />
<input type="hidden" name="state" value="/api/ticketing/issueTopics" />
<input type="hidden" name="session_state" value="<removed>" />
<noscript>
<p>Script is disabled. Click Submit to continue.</p>
<input type="submit" value="Submit" />
</noscript>
</form>
<script language="javascript">document.forms[0].submit();</script>
</body>

我删除的不记名 token 在反序列化时包含我的信息,而不是我的消费应用程序。因此,它试图对我进行身份验证,而不是使用不记名 token 进行身份验证。

有什么想法可以解决这个问题吗?

更新1

通过更新,我提取了与我的消费应用程序相关的 servicePrincipal 数据,它清楚地表明消费应用程序应该能够与 API 应用程序通信。

    "oauth2Permissions": [{
"adminConsentDescription": "Allow the application to access Ticketing API on behalf of the signed-in user.",
"adminConsentDisplayName": "Access Ticketing API",
"id": "<removed>",
"isEnabled": true,
"type": "User",
"userConsentDescription": "Allow the application to access Ticketing API on your behalf.",
"userConsentDisplayName": "Access Ticketing API",
"value": "user_impersonation"
}]

更新2

我制作了一个控制台应用程序来尝试这种方式。我收到了 401(未经授权)。

一个有趣的观察是,如果我访问 jwt.io 并粘贴我的 token ,它能够反序列化它,但它也说 token 无效(无效签名)。不确定这意味着什么。

最佳答案

在弄清楚如何打开详细日志记录并通过它们进行分析后,我解决了这个问题。

MSDN 上的文档表示将“资源”作为 App ID Uri 传递。但实际上您需要将客户端 ID 作为“资源”的值传递。一旦我改变了它,一切就完美了。

我在 LogFiles\Application 的 txt 文件中找到了这个。

2016-07-12T15:48:39  PID[8584] Warning     JWT validation failed: IDX10214: Audience validation failed. Audiences: 'https://<removed>.azurewebsites.net'. Did not match:  validationParameters.ValidAudience: '0b61abb8-59...7-6046c22f9c92' or validationParameters.ValidAudiences: 'null'.

我查看的文档不正确:

https://msdn.microsoft.com/en-us/library/partnercenter/dn974935.aspx https://msdn.microsoft.com/en-us/library/azure/dn645543.aspx (这是最大的罪犯,因为它完全按照我想要的方式处理不正确的信息)

关于azure - 无法使用不记名 token 访问 AAD 安全 Web API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38332313/

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