/// <summary> /// Ensure that the user in the destination Okta tenant exists and exactly matches the provided one /// </summary> /// <param name="client">A configured Okta IUserClient</param> /// <param name="targetState">The target state of the user</param> /// <param name="cancellationToken">Cancellation token</param> public static async Task Ensure(this IUsersClient client, User targetState, CancellationToken cancellationToken) { var currentState = await GetIfExists(() => client.GetUserAsync(targetState.Profile.Login, cancellationToken)); if (currentState.CurrentState != EntityState <IUser> .State.DoesNotExist) { //If it exists already, but doesn't match, then we need to override it await client.UpdateUserAsync(targetState, currentState.Entity.Id, cancellationToken); } else { await client.CreateUserAsync(targetState, activate : true, provider : false, nextLogin : null, //Don't prompt for password change cancellationToken : cancellationToken); } }