Power Automate 自定义连接器 - 令牌无效、受众无效

Power Automate Custom Connector - Token Invalid, Invalid Audience

我之前构建了一些自定义连接器,但由于某种原因,我在获取自定义连接器以根据我编写的 api 进行身份验证时遇到了实际问题。

API 是用 .netcore 5 编写的,作为 WebApp 在我尝试连接的同一个租户中托管。我检查了身份验证设置,ClientId 指向下图中的 37008370 clientid guid。

这就是我在连接器中设置身份验证的方式

我已经使用 Blazor 应用程序连接到此 API,因此我认为身份验证设置正确。

当我尝试为自定义连接器设置身份验证时,虽然收到以下响应

{  "content-length": "0",  "date": "Wed, 20 Oct 2021 10:11:51 GMT",  "request-context": appId=cid-v1:4e1e4b6a-ace8-48e9-8121-546d6e834953",  "www-authenticate": "Bearer error=\"invalid_token\", error_description=\"The audience 'api://37008370-*********' is invalid\"",  "x-ms-apihub-cached-response": "false",  "x-powered-by": "ASP.NET"}

我想我已经正确设置了所有内容,但看不出哪里出错了。

感谢任何帮助。

谢谢

斯图尔特

令牌的受众应始终与应用程序的客户端 ID 匹配registered.The错误原因相同。受众是 api://xxxx-xx 和客户 ID=3700-xxx。 资源可以是资源的 App ID GUID,或在资源上注册的有效 App ID URI。 AAD 应该能够根据您提供的值识别您尝试访问的资源。

Note that if you use an App ID GUID, you will get a token from AAD where the Audience claim is the App ID GUID. Alternatively, if you use an App ID URI, you will see that URI as the audience claim in the token.

所以这里你需要在应用程序设置中添加clientId :api://xxxxx-xxxx(这是应用程序ID uri,存在于公开的api blade of the azure ad app app registration portal)代码 .

Azure 为令牌生成的“aud”值也由 AD 应用程序清单中的“accessTokenAcceptedVersion”属性 控制。

此 属性 定义将生成的访问令牌的版本。 检查 http://jwt.io 中的 jwt 令牌如果你得到这个。 检查您的 azure 广告清单。app"accessTokenAcceptedVersion" 属性 值可能是 null 或 one,或者应该是 two。如果为 null,则可以考虑添加 api:// 前缀。 else api:// 前缀可以忽略。