[英]Add a security group to a security group fails with Request_BadRequest
[英]C# Microsoft Graph Api Request_BadRequest
每次我嘗試在 C# 中使用 Microsoft Graph Api 向用戶添加許可證時,我都會收到此錯誤:
Microsoft.Graph.ServiceException: '代碼:Request_BadRequest 消息:無法為使用位置無效的用戶分配許可證。
我的代碼在這里
using Azure.Identity;
using Microsoft.Graph;
var scopes = new[] { "https://graph.microsoft.com/.default" };
var tenantId = "tenantid";
var clientId = "clientid";
var clientSecret = "clientsecret";
var options = new TokenCredentialOptions
{
AuthorityHost = AzureAuthorityHosts.AzurePublicCloud
};
var clientSecretCredential = new ClientSecretCredential(
tenantId, clientId, clientSecret, options);
var graphClient = new GraphServiceClient(clientSecretCredential, scopes);
var user = new User
{
AccountEnabled = true,
DisplayName = "test",
MailNickname = "test",
UserPrincipalName = "test@example.com",
PasswordProfile = new PasswordProfile
{
ForceChangePasswordNextSignIn = true,
Password = "random.1234"
}
};
var addLicenses = new List<AssignedLicense>()
{
new AssignedLicense
{
SkuId = Guid.Parse("314c4481-f395-4525-be8b-2ec4bb1e9d91")
}
};
var removeLicenses = Array.Empty<Guid>();
await graphClient.Users
.Request()
.AddAsync(user);
Console.WriteLine("Kullanıcı Açıldı");
await graphClient.Users["test@example.com"]
.AssignLicense(addLicenses, removeLicenses)
.Request()
.PostAsync();
Console.WriteLine("Lisans Eklendi");
創建新用戶時,您需要設置UsageLocation
。
文檔說usageLocation
對於將被分配許可證的用戶是必需的,因為法律要求檢查國家/地區的服務可用性。
var user = new User
{
AccountEnabled = true,
DisplayName = "test",
MailNickname = "test",
UserPrincipalName = "test@example.com",
PasswordProfile = new PasswordProfile
{
ForceChangePasswordNextSignIn = true,
Password = "random.1234"
},
UsageLocation = "TR" // for Turkey
};
// rest of the code without changes
var addLicenses = new List<AssignedLicense>()
{
new AssignedLicense
{
SkuId = Guid.Parse("314c4481-f395-4525-be8b-2ec4bb1e9d91")
}
};
var removeLicenses = Array.Empty<Guid>();
await graphClient.Users
.Request()
.AddAsync(user);
Console.WriteLine("Kullanıcı Açıldı");
await graphClient.Users["test@example.com"]
.AssignLicense(addLicenses, removeLicenses)
.Request()
.PostAsync();
Console.WriteLine("Lisans Eklendi");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.