我想通过其客户端凭证直接访问一个 API,而不是通过任何 Web 应用程序
private async Task<string> GetAutheticationToken(string APITypeSelected, string APIKeySelected=null)
{
string aadInstance = ConfigurationManager.AppSettings["ida:AADInstance"];
string tenant = ConfigurationManager.AppSettings["ida:AADTenant"];
string appKey = ConfigurationManager.AppSettings[APIKeySelected];
string apiID = ConfigurationManager.AppSettings[APITypeSelected];
//appKey = HttpUtility.UrlEncode(appKey);
string authority = String.Format(CultureInfo.InvariantCulture, aadInstance, tenant);
using (HttpClient client = new HttpClient())
{
Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext authContext = null;
ClientCredential clientCredential = null;
authContext = new Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext(authority);
//encodeURIComponent(client_secret);
clientCredential = new ClientCredential(apiID, appKey);
AuthenticationResult authResult = null;
authResult = await authContext.AcquireTokenAsync(apiID, clientCredential);
return authResult.AccessToken;
}
}
执行时我在这一行收到以下错误(AADSTS501051)
authResult = await authContext.AcquireTokenAsync(apiID, clientCredential);
AADSTS501051:应用程序“{API GUID}”(DEV-API) 未分配给应用程序“{API GUID}”(DEV-API) 的角色。
我是否必须向其自身授予 API 权限?
我需要做什么。
天涯尽头无女友
幕布斯6054654
慕尼黑的夜晚无繁华
月关宝盒
相关分类