Hi - I see when you log a new external user in using OnAuthentication that the docs say do this to add a role
// Initialize a hash table mapping roles to sites for the user
Hashtable rolesTable = new Hashtable();
// Get the code name of the current site
string siteName = CMSContext.CurrentSite.SiteName;
// Assign the user to the current site
usr.SitesRoles[siteName.ToLower()] = rolesTable;
// Add new role "external role" to the hash table to assign it to the user
rolesTable["external role"] = 0;
but if the user already exists, this code (along with the rest of the UserInfo creation code before it in the sample) replaces all the roles a user has. E.g. if the user has been in kentico for a month and is both an external user in "external role", but also has been manually added to "CMS Editors" too, then the code above replaces his 2 roles with just "external role".
So I tried to see if the user exists and just add the role I want like this... but it does nothing.
usr = UserInfoProvider.GetFullUserInfo(osaUser.Email);
if (usr != null) {
if (!usr.IsInSite(siteName))
UserInfoProvider.AddUserToSite(usr.UserName, siteName);
if (!usr.IsInRole(role, siteName))
UserInfoProvider.AddUserToRole(usr.UserName, role, siteName);
}
even tried throwing in a UserInfoProvider.SetUserInfo(usr);
but still nothing
Does OnAuthentication allow updates .. or is the whole external user solution based around rebuilding roles from an external system everytime?
thanks