Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Maff 141 posts 466 karma points
    Apr 26, 2016 @ 15:03
    Maff
    0

    Can't save properties on UmbracoApplicationMember

    Hi all,

    I'm adding an external SSO to Umbraco 7 using Shannon's Identity package, all works fine until I try to add extra data to the newly created Umbraco Member.

    Here's the code I'm running:

            private async Task<IdentityResult> AddMemberProperties(UmbracoApplicationMember umbracoMember, string firstName, string lastName, string ssoId)
            {
    
            UmbracoApplicationMember existingUmbracoMember = await UserManager.FindByIdAsync(umbracoMember.Id);
    
            existingUmbracoMember.Roles.Add(new IdentityMemberRole { RoleName = "GroupMember", UserId = existingUmbracoMember.Id });
    
            foreach (UmbracoProperty memberProperty in existingUmbracoMember.MemberProperties)
            {
                if (memberProperty.Alias == "firstName")
                    memberProperty.Value = firstName;
    
                if (memberProperty.Alias == "lastName")
                    memberProperty.Value = lastName;
    
                if (memberProperty.Alias == "ssoId")
                    memberProperty.Value = ssoId;
            }
    
            return await UserManager.UpdateAsync(existingUmbracoMember);
            }
    

    This is executed as part of the "ExternalLoginCallback" method on the UmbracoIdentityAccountController, after the Umbraco member has been successfully created.

    The "UpdateAsync" call comes back with a success and the group is successfully being assigned, but when I check in the back-office the firstName, lastName and ssoId properties aren't saved to the Member.

    I've probably missed something very basic, but Google isn't being very helpful with this today...

    Thanks,

    Maff

  • Maff 141 posts 466 karma points
    Apr 26, 2016 @ 15:57
    Maff
    0

    Just got it working using a slightly different approach (https://twitter.com/SimonAntony/status/724987064886939648) - thanks Simon!

    I used the MemberService to set the properties and save them:

            IMemberService memberService = Services.MemberService;
    
            IMember member = memberService.GetById(umbracoMember.Id);
    
            member.SetValue("firstName", firstName);
            member.SetValue("lastName", lastName);
            member.SetValue("ssoId", ssoId);
    
            memberService.Save(member);
    

    Not sure why my initial approach hasn't worked, and would still be interested if anyone can suggest how to get it working!

    But anyway it works now, and that's good enough for rock and roll! :)

Please Sign in or register to post replies

Write your reply to:

Draft