因此,我正在try 将新的应用程序角色添加到我的Azure Active Directory应用程序.
请注意,在My Azure的API权限中,我在以下项下添加了添加读/写权限:用户、文件、角色管理和应用程序
我的代码是:
using Azure.Identity;
using Microsoft.Graph;
using Microsoft.Graph.Models;
public async Task<string> TestAsync()
{
var scopes = new[] { "https://graph.microsoft.com/.default" };
string clientId = "....";
string tenantId = "....";
string clientSecret = "...."; //Value and not Id
string objectId = "....";
var options = new TokenCredentialOptions
{
AuthorityHost = AzureAuthorityHosts.AzurePublicCloud
};
var clientSecretCredential = new ClientSecretCredential(tenantId, clientId, clientSecret, options);
var graphClient = new GraphServiceClient(clientSecretCredential, scopes);
var requestBody = new Application
{
AppRoles = new List<AppRole>
{
new AppRole
{
AllowedMemberTypes = new List<string>
{
"User",
"Application",
},
Description = "TestRole1",
DisplayName = "TestRole1",
Id = Guid.NewGuid(),
IsEnabled = true,
Origin = "Application",
Value = "test.write",
}
}
};
var result = await graphClient.Applications[objectId].PatchAsync(requestBody);
return "role added!";
}
但是代码抛出了这个异常,并且NULL中的内部异常"抛出了‘Microsoft.Graph.Models.ODataErrors.ODataError’类型的异常".
我错过了什么?