Creating user/Associate with AD authentication

Hi

Do you have an example of how to create a new user that is authenticated through Active Directory, using the UserAgent?

 

RE: Creating user/Associate with AD authentication

Hi Snorre,

If a person in SuperOffice already exists, you can use this method.

public static User CreateUser(int personId, string adUserName, string adUserSid, int roleId, int priGroupId)
{
    using (UserAgent userAgent = new UserAgent())
    {
        var credTypes = userAgent.GetCredentialTypes();
        var adCred = credTypes.FirstOrDefault(c => c.Type == "ActiveDirectory");

        var associate = userAgent.CreateDefaultUserFromUserTypeAndPersonId(UserType.InternalAssociate, personId);

        associate.Credentials = new[] { new Credential()
        {
            Type = adCred,
            Value = adUserSid,
            DisplayValue = adUserName
        }};


        associate.Role = new Role() { Id = roleId };
        associate.UserGroup = new UserGroup() { Id = priGroupId };
        associate.Name = adUserName;
        return userAgent.SaveUser(associate);
    }
}

If you want to create the user and person automatically from AD, use this method.

public static User CreateADUserOnContact(int contactId, string adUserName, string adUserSid, int roleId, int priGroupId)
{
    using (UserAgent userAgent = new UserAgent())
    {

        var associate = userAgent.CreateDefaultUserFromUserTypeAndCredential(UserType.InternalAssociate, 
            contactId, "ActiveDirectory", adUserSid, adUserName);

        associate.Role = new Role() { Id = roleId };
        associate.UserGroup = new UserGroup() { Id = priGroupId };
        associate.Name = adUserName;

        return userAgent.SaveUser(associate);
    }
}

Assigning licenses is a different thread.

Hope this helps!

 

By: Tony Yates 27 Apr 2017