我正在尝试构建一个 WebAPI 并希望使用范围来限制其他客户端应用程序的权限。我在“公开 API”边栏选项卡上创建了一个范围“BuildingAccess”,并将其他客户端应用程序添加到具有该范围的授权列表中。但是,当我使用客户端程序尝试获取具有该范围的令牌时,我得到“AADSTS70011: The provided request must include a 'scope' input parameter. The provided value for the input parameter 'scope' is not valid.
" error
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.SecurityTokenInvalidAudienceException'
在 Microsoft.IdentityModel.Tokens.dll 中
我在客户端收到未经授权的回复。
1.您应该输入正确的格式范围,确保使用以下格式:api://{Your-Application-ID}/your_scope_name。
2.Then you should grant permissions to the API and select the administrator to agree.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)