azure - 我在 Azure 中执行了“公开 API”,但无法将该范围的令牌提供给客户端程序
问题描述
我正在尝试构建 WebAPI 并希望使用范围来限制其他客户端应用程序的权限。我在 Expose an API 刀片上创建了一个范围“BuildingAccess”,并将其他客户端应用程序添加到具有该范围的授权列表中。但是,当我使用客户端程序尝试获取具有该范围的令牌时,我得到“ AADSTS70011: The provided request must include a 'scope' input parameter. The provided value for the input parameter 'scope' is not valid.
”错误
IConfidentialClientApplication app = ConfidentialClientApplicationBuilder.Create("removed")
.WithTenantId("removed")
.WithClientSecret(ClientSecret)
.Build();
List<string> scopes = new List<string>();
scopes.Add(".default");
scopes.Add("https://localhost:44371/BuildingAccess");
AuthenticationResult result = null;
try
{
result = await app.AcquireTokenForClient(scopes).ExecuteAsync();
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Token acquired \n");
Console.ResetColor();
}
catch (MsalServiceException ex)
when (ex.Message.Contains("AADSTS70011"))
{
// Invalid scope. The scope has to be of the form "https://resourceurl/.default"
// Mitigation: change the scope to be as expected
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Scope provided is not supported");
Console.ResetColor();
}
唯一可行的格式是当范围设置为https://localhost:44371/.default 时。下面我添加 BuildingAccess 范围的所有其他组合都失败,并针对我尝试过的不同格式出现以下错误。
- 范围
api://333333-2222-1111-0000-aaaaaaaaaaaaa/BuildingAccess https://localhost:44371/.default
无效。 - 范围
api://333333-2222-1111-0000-aaaaaaaaaaaaa/.default api://333333-2222-1111-0000-aaaaaaaaaaaaa/BuildingAccess
无效。 - 范围
.default BuildingAccess
无效。 - 范围
BuildingAccess
无效。 - 范围
api://333333-2222-1111-0000-aaaaaaaaaaaaa/BuildingAccess
- 范围
https://localhost:44371/BuildingAccess
无效。
如果那个有效https://localhost:44371/.default
,那么我的服务器端有一个错误,因为它失败了
抛出异常:Microsoft.IdentityModel.Tokens.dll 中的“Microsoft.IdentityModel.Tokens.SecurityTokenInvalidAudienceException”
我在客户端收到未经授权的响应。
解决方案
推荐阅读
- php - PHP/MYSQL 错误:mysqli_result 类的对象无法转换为字符串
- sqlite - 无法加载 SQLite3.dll!Autohotkey 未发现错误
- ocr - Nativescript OCR 失败并出现一般错误
- python - 如何根据 NaN 之后的下一个有效值等于上一个有效值的条件回填 NaN 值
- google-apps-script - 如果单元格的值低于某个值,则发送电子邮件
- c++ - C++ 模板模板参数
- mysql - 列表包含非聚合列“otpallet_pokemonpalet.p.id”
- java - 为什么我的解决方案不能找到二叉树的最小深度?
- coq - 注入策略能否修改最终目标,或添加无关假设?
- java - [JAVA} A-Star 代码未找到最佳路径