gpt4 book ai didi

azure - 我在 Azure 中执行了 "Expose an API",但无法将该范围的 token 获取到客户端程序

转载 作者:行者123 更新时间:2023-12-03 02:40:51 25 4
gpt4 key购买 nike

我正在尝试构建 WebAPI,并希望使用范围来限制其他客户端应用程序的权限。我在“公开 API”边栏选项卡上创建了一个范围“BuildingAccess”,并将其他客户端应用程序添加到具有该范围的授权列表中。但是,当我使用客户端程序尝试获取具有该范围的 token 时,我收到“AADSTS70011:提供的请求必须包含“范围”输入参数。输入参数“范围”的提供值无效.”错误

 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,那么我的服务器端会出现错误,因为它失败了

Exception thrown: 'Microsoft.IdentityModel.Tokens.SecurityTokenInvalidAudienceException' in Microsoft.IdentityModel.Tokens.dll

我在客户端收到未经授权的响应。

最佳答案

1.您应该输入正确的格式范围,确保使用以下格式:api://{Your-Application-ID}/your_scope_name。

2.然后您应该向API授予权限并选择管理员同意。 enter image description here

关于azure - 我在 Azure 中执行了 "Expose an API",但无法将该范围的 token 获取到客户端程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61375072/

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