Copied to clipboard

Flag this post as spam?

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


  • kajal_sawant 10 posts 113 karma points
    Dec 19, 2018 @ 11:50
    kajal_sawant
    0

    GetUserTypeByName show error while implementing Azure Ad in Umbraco

    Hello,

    i am try to implement Azure AD in umbraco in UmbracoADAuthExtensions.cs.
    i am using umbraco version="7.12.4"
    i got an error in GetUserTypeByName shows error like

    " Iuserservice does not contain a definition for 'IUserService' does not contain a definition for 'GetUserTypeByName' and no accessible extension method 'GetUserTypeByName' accepting a first argument of type 'IUserService' could be found (are you missing a using directive or an assembly reference?)

    var writerUserType = userService.GetUserTypeByName("writer");
    Can anyone please tell me what wrong ? Thank you.

     var adOptions = new OpenIdConnectAuthenticationOptions
                {
                    SignInAsAuthenticationType = Constants.Security.BackOfficeExternalAuthenticationType,
                    ClientId = clientId,
                    Authority = authority,
                    RedirectUri = postLoginRedirectUri,
                    AuthenticationMode = AuthenticationMode.Passive,
                    Notifications = new OpenIdConnectAuthenticationNotifications
                    {
                        AuthorizationCodeReceived = async context =>
                        {
                            var userService = ApplicationContext.Current.Services.UserService;
    
                            var email = context.JwtSecurityToken.Claims.First(x => x.Type == "email").Value;
                            var issuer = context.JwtSecurityToken.Claims.First(x => x.Type == "iss").Value;
                            var providerKey = context.JwtSecurityToken.Claims.First(x => x.Type == "sub").Value;
                            var name = context.JwtSecurityToken.Claims.First(x => x.Type == "name").Value;
                            var userManager = context.OwinContext.GetUserManager<BackOfficeUserManager>();
    
                            var user = userService.GetByEmail(email);
    
                            if (user == null)
                            {
                                var writerUserType = userService.GetUserTypeByName("writer");
                                user = userService.CreateUserWithIdentity(email, email, writerUserType);
                            }
    
                            var identity = await userManager.FindByEmailAsync(email);
                            if (identity.Logins.All(x => x.ProviderKey != providerKey))
                            {
                                identity.Logins.Add(new IdentityUserLogin(issuer, providerKey, user.Id));
                                identity.Name = name;
                                await userManager.UpdateAsync(identity);
                            }
                        }
                    }
                };
    
  • Marcio Goularte 388 posts 1360 karma points
    Dec 19, 2018 @ 13:03
    Marcio Goularte
    100

    Hi,

    You probably should have done an Umbraco version upgrade. Since version 7.7 user types have been replaced by user groups

    https://umbraco.com/blog/umbraco-77-beta-beautiful-user-management-is-now-a-thing/

    The method has been replaced by this:

    https://github.com/umbraco/Umbraco-CMS/blob/dev-v7/src/Umbraco.Core/Services/UserService.cs#L898

    Example of how to add the user to the group:

       //get group
       var group = _userService.GetUserGroupByAlias("writer") as IReadOnlyUserGroup;
    
       // how to add a group to user
       user.AddGroup(group );
    
       // save user
       _userService.Save(user);
    

    example of this post https://our.umbraco.com/forum/using-umbraco-and-getting-started/92606-how-to-add-a-group-to-a-user

  • kajal_sawant 10 posts 113 karma points
    Dec 19, 2018 @ 13:23
    kajal_sawant
    0

    Hello @MarcioGoularte

    Thank you so much for Guidance. It's Help me alot :).

Please Sign in or register to post replies

Write your reply to:

Draft