【发布时间】:2019-11-19 22:12:35
【问题描述】:
我正在编写一个连接的控制台应用程序,以帮助自动执行即将进行的租户迁移。
我要做的是从当前租户中删除自定义域的所有关联,以便我可以将它们添加到新租户。
到目前为止我所拥有的:
ConsoleApp 已向 AAD 注册,并且已分配 API 权限并获得同意。
我已导入以下内容:
using Microsoft.Graph;
using Microsoft.Graph.Auth;
using Microsoft.Identity.Client
初始化一个graphClient:
GraphServiceClient graphClient = new GraphServiceClient(authProvider);
并成功地对图表进行了.GetAsync 调用。
我需要什么帮助:
我正在尝试将群组的电子邮件更新为 'gItem.mailNickname@tenantID'。我有一个错误说“邮件字段是只读的”。通过图形资源管理器,我注意到 proxyAddresses 字段包含该组的所有别名,并且邮件被列为“SMPT:...”我试图用
proxyAddresses 字段
var upGroup = await graphClient
.Groups["4f629be4-f592-4520-b80d-7570f68e276e"]
.Request()
.GetAsync();
var updateFields = new Group
{
ProxyAddresses = new List<string>()
{
"SMPT:" + upGroup.MailNickname + "@" + tenantID,
}
};
await graphClient
.Groups[upGroup.Id]
.Request()
.UpdateAsync(updateFields);
我收到权限不足的错误消息,但我已检查 AAD 以确保 Directory.ReadWrite.All 和 Groups.ReadWrite.All 均已配置和授予。
其他组属性可以更改,这导致我质疑我在 proxyAddresses 属性上的结构。
代码添加到列表失败
var updateFields = new Group
{
ProxyAddresses = new string[] { "SMTP:" + upGroup.MailNickname + "@" + tenantID }
};
完整代码:
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Graph;
using Microsoft.Graph.Auth;
using Microsoft.Identity.Client;
namespace RemoveGroupAliases
{
class Program
{
private static string clientId = "";
private static string tenantID = "";
private static string clientSecret = "";
private static IConfidentialClientApplication confidentialClientApplication = ConfidentialClientApplicationBuilder
.Create(clientId)
.WithTenantId(tenantID)
.WithClientSecret(clientSecret)
.Build();
static ClientCredentialProvider authProvider = new ClientCredentialProvider(confidentialClientApplication);
static async Task Main(string[] args)
{
GraphServiceClient graphClient = new GraphServiceClient(authProvider);
var groups = await graphClient
.Groups
.Request()
.Filter("mailEnabled+eq+true")
.GetAsync();
foreach (var tgroup in groups)
{
Console.WriteLine(tgroup.Id);
Console.WriteLine(tgroup.DisplayName);
};
var upGroup = await graphClient
.Groups["4f629be4-f592-4520-b80d-7570f68e276e"]
.Request()
.GetAsync();
var updateFields = new Group
{
ProxyAddresses = new List<String>()
{
"SMTP:" + upGroup.MailNickname + "@" + tenantID
}
};
await graphClient
.Groups[upGroup.Id]
.Request()
.UpdateAsync(updateFields);
Console.ReadLine();
}
}
}
这个想法是拉出所有启用邮件的组并删除所有域,以便我可以将其从该租户中删除并将其关联到新租户。切换域后,我将有一个不同的程序来分配域和别名。当我将鼠标悬停在 proxyAddresses 的工具提示上时,最后一行显示“只读”,这可能是我的问题,但我没有将其视为错误。
【问题讨论】:
-
Proxyaddress 只能接受一个 'SMTP' 地址,其他地址必须是 'smtp'。这可能是你的问题吗?
-
我首先要替换整个字段值。即使使用更正的 SMTP,CreateAsync (Post) 也会收到目标不允许 HTTP 方法的错误。
-
我已经完成并创建了一个新的应用程序注册,并在继续测试之前确保它具有管理员同意绿色复选标记。
var updateFields = new Group { ProxyAddresses = new List<String> { "SMTP:test.permissions@lonestarsecure.com", "smtp:test.permissions@5DShield.com" } }; await graphClient.Groups[upGroup.Id] .Request() .UpdateAsync(updateFields);还是没有运气 -
更新:控制台程序成功更新了描述字段,这让我相信问题在于构建 ProxyAddresses 字段的构造。有什么想法吗?
-
你能发布一个包含 JSON 在内的整个 HTTP 请求的 pastebin 吗? (不要忘记编辑任何私钥等)
标签: c# microsoft-graph-api microsoft-graph-sdks