Delay when adding user

1.2k views Asked by At

I am adding a user to AAD and following adding the user to a group. However it is like there is a small delay before the user us added. Is the expected behavior? If yes how long can you expect this delay?

In the code below adding the user to the group fails because user is null. After some seconds however I can add it. To implement this I need to know what the expected delay is. Can it be minutes or hours?

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);
1

There are 1 answers

0
unknown On BEST ANSWER

It can be confirmed that there is a delay when adding user with Azure. It is always 5-10mins, but I couldn't make sure the time of delay.

It seems better to check if the user has been added, then you could add it into groups. You can use the Graph API and query for the user you want, like this:

https://graph.microsoft.com/v1.0/users?$filter=startswith(userPrincipalName,'[email protected]')

This is a code sample for you to refer.