Skip to content

Instantly share code, notes, and snippets.

@Sam7
Created March 9, 2018 04:48
Show Gist options
  • Save Sam7/e9bf2c2ed23d2caf370423d68035b3c9 to your computer and use it in GitHub Desktop.
Save Sam7/e9bf2c2ed23d2caf370423d68035b3c9 to your computer and use it in GitHub Desktop.
UmbracoCustomOwinStartup.AddGroups.cs
private static void AddGroups(BackOfficeIdentityUser autoLinkUser, IEnumerable<string> groupsToAdd, Dictionary<string, Claim> adGroupNames)
{
// add new groups
foreach (var adGroup in groupsToAdd.Where(s => !string.IsNullOrWhiteSpace(s)))
{
var userService = UmbracoContext.Current.Application.Services.UserService;
var userGroup = userService.GetUserGroupByAlias(adGroup);
if (userGroup == null)
{
// Create new Group without permissions. They have to be
userGroup = new UserGroup { Alias = adGroup, Name = GroupLabelPrefix + adGroupNames[adGroup].Value };
userService.Save(userGroup);
}
autoLinkUser.AddRole(userGroup.Alias);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment