添加用户时延迟

问题描述

我要将用户添加到AAD,然后将用户添加到组。但是,这就像在我们添加用户之前有一个小的延迟。是预期的行为吗?如果是,您预计会有多长时间?

在下面的代码中,由于user为null,因此无法将用户添加到组中。几秒钟后,我可以添加它。为了实现这一点,我需要知道预期的延迟是多少。可以是几分钟还是几小时?

var email = "xxx";

var graphClient = await Graph.GraphServiceClientExtension.GetGraphClient( _config.AzureAppIdExternal,_config.AzureAppSecretExternal,_config.TenantNameExternal);

var invite = new Microsoft.Graph.Invitation();
invite.InvitedUserEmailAddress = email;
invite.InvitedUserdisplayName = email;

invite.InviteRedirectUrl = "xxx";
invite.SendInvitationMessage = true;

var inviteMsginfo = new Microsoft.Graph.InvitedUserMessageInfo();
inviteMsginfo.CustomizedMessageBody = "Velkommen,xx";
invite.InvitedUserMessageInfo = inviteMsginfo;

var inviteUserResponse = await graphClient.Invitations.Request().AddAsync(invite);
var user = (await graphClient.Users.Request().Filter($"mail eq '{email}'").GetAsync()).FirstOrDefault();

await graphClient.Groups["xx-7b17-4ed7-9b75-xx"].Members.References.Request().AddAsync(user);

解决方法

可以确认在使用Azure添加用户时存在延迟。总是5-10分钟,但我不能确定延迟的时间。

检查是否已添加用户似乎更好,然后可以将其添加到组中。您可以使用Graph API并查询所需的用户,如下所示:

https://graph.microsoft.com/v1.0/users?$filter=startswith(userPrincipalName,'someuser@mytenant.onmicrosoft.com')

这是code sample供您参考。