Copied to clipboard

Flag this post as spam?

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


  • Jeroen Breuer 4909 posts 12266 karma points MVP 5x admin c-trib
    Jul 20, 2022 @ 07:51
    Jeroen Breuer
    1

    External login providers with virtual users/members

    Hi all,

    I'm doing some experiments with external login providers. The following docs have been really helpful:

    https://our.umbraco.com/documentation/reference/security/external-login-providers/

    https://our.umbraco.com/documentation/reference/security/auto-linking/

    The auto-linking feature seems like a great addition because you don't need to create users/members first in the backoffice.

    I have a working example with an external login provider and auto-linking. It works, but when a user/member does an external login it will still create a user/member in the backoffice. Since my external login provider is the source of truth for all users/members I don't need them in the backoffice. Is there something like virtual user/member that only exists while being logged in? Something similar to this feature in Sitecore: https://doc.sitecore.com/xp/en/developers/92/sitecore-experience-manager/configure-federated-authentication.html#configure-virtual-and-persistent-users

    My external login provider has thousands of users/members and I don't need all of them in my Umbraco backoffice. Is that possible?

    Jeroen

  • Jeroen Breuer 4909 posts 12266 karma points MVP 5x admin c-trib
    Jul 26, 2022 @ 14:27
    Jeroen Breuer
    101

    Hi all,

    I've checked the source code of Umbraco and it seems that virtual users/members are not supported at the moment.

    That's why I created a feature request for it: https://github.com/umbraco/Umbraco-CMS/discussions/12741

    Jeroen

  • Guido Adam 23 posts 67 karma points
    Aug 08, 2022 @ 16:02
    Guido Adam
    0

    Hi, could this be something on the OnExternalLogin method? It's not a virtual user, but i guess you have to hook up on a database anyway to do your check.

     public void Configure(BackOfficeExternalLoginProviderOptions options)
        {
            options.AutoLinkOptions = new ExternalSignInAutoLinkOptions(
                            autoLinkExternalAccount: false )
    
        {
                        OnExternalLogin = (user, loginInfo) =>
                        {
                            // Do your check on your DB
    
                            return true; //returns a boolean if sign in should continue
                        }
                    };
        }
        }
    
  • Jeroen Breuer 4909 posts 12266 karma points MVP 5x admin c-trib
    Aug 09, 2022 @ 07:09
    Jeroen Breuer
    0

    Hi Guido,

    Unfortunately that won't work because the OnExternalLogin event is only triggered after the OnAutoLinking event. So it will only trigger if a user/member already exists in Umbraco.

    Jeroen

  • Jeroen Breuer 4909 posts 12266 karma points MVP 5x admin c-trib
    Sep 01, 2022 @ 09:44
    Jeroen Breuer
    0

    It's still not possible to use virtual users/members.

    However I did release a package that shows how external login providers can be used in Umbraco: https://www.jeroenbreuer.nl/blog/released-umbraco-openid-connect-example-package/

    Jeroen

  • Andreas Kristensen 77 posts 301 karma points c-trib
    Nov 04, 2022 @ 11:43
    Andreas Kristensen
    2

    I think I have some pointer, that can help you to a solution. I am currently working on a somewhat similar problem.

    I have yet to make it fully integrate into Umbraco member system, but here is some pointers:

    You can have a look at creating a class that inherits from Umbraco.Cms.Web.Common.Security.MemberManager. (Also check this out) You can then inject that in startup like this:

    services.AddUmbraco(_env, _config)
                .AddBackOffice()
                .AddWebsite()
                .AddComposers()
                .SetMemberManager<YourMemberManagerClass>()
                .Build();
    

    In that class, you can override almost all the action you need. I have not had a look at this yet, but there is also a .SetMemberStore() method on the IServiceCollection, so that might be helpfull as well.

    When you look into MemberManager and it's dependencies, you find a lot of functionality that can possibly help you figure out a solution.

    This was very helpfull for me, when I had to store custom data on the member.

    The very most simple thing you can do, is something like this, in you auth controller. It will not get you all the way, buy it will get you logged in.

    var user = new MemberIdentityUser
                    {
                        Id = "someId",
                        UserName = "someUsername"
                    };
    
                    user.Claims.Add(new IdentityUserClaim<string>() { ClaimType = ClaimTypes.Role, ClaimValue = "role goes here" });
    
                    await _memberSigninManager.SignInAsync(user, true);
    

    _memberSigninManager is type IMemberSignInManager.

    As mentioned, I havent gotten it all fully integrated. I am still having trouble getting the member to access protected nodes.

    I know that this is all over the place, but I thought it might be to some help.

  • Thomas 319 posts 606 karma points c-trib
    Nov 04, 2022 @ 11:55
    Thomas
    0

    Perfect timing :D Where just looking for something like this!

  • Andreas Kristensen 77 posts 301 karma points c-trib
    Nov 04, 2022 @ 12:02
    Andreas Kristensen
    1

    Haha! Awesome!

    I have been buried in this for the last couple of days. I must say, the documentation is very lacking on this area. I stitched this together from forum posts, documentation and source code, and it's not even fully working (but enought for what I need right now).

    But since there is so little information, I thought I would hurry and get my findings out there. So hopefully it helps :)

  • Thomas 319 posts 606 karma points c-trib
    Nov 07, 2022 @ 08:09
    Thomas
    0

    It's like the role are not added to the user.

    It says the user is logged in..

  • Jeroen Breuer 4909 posts 12266 karma points MVP 5x admin c-trib
    Nov 22, 2022 @ 09:58
    Jeroen Breuer
    0

    Hi Andreas,

    Did you manage to get virtual users/members working in Umbraco?

    Jeroen

  • Andreas Kristensen 77 posts 301 karma points c-trib
    Nov 22, 2022 @ 10:03
    Andreas Kristensen
    1

    Hi Jeroen,

    I have only come as far as described above, as I have not had time to look at it. I might need to look into it in the coming months though.

  • Thomas 319 posts 606 karma points c-trib
    Nov 22, 2022 @ 10:05
    Thomas
    0

    Same. For now I'm creating the Member in Umbraco on login

  • Jeroen Breuer 4909 posts 12266 karma points MVP 5x admin c-trib
    Jan 13, 2023 @ 07:47
    Jeroen Breuer
    1

    Hi Andreas,

    I'm going to do some experiments with virtual users. Starting with the pointers you gave in this topic. Do you have any other tips?

    Jeroen

  • Jeroen Breuer 4909 posts 12266 karma points MVP 5x admin c-trib
    Jan 13, 2023 @ 17:07
    Jeroen Breuer
    1

    I've been able get a part of virtual members working. You can login and the member doesn't need to exist in Umbraco. You can find the experimental code here:

    https://github.com/jbreuer/Umbraco-OpenIdConnect-Example/blob/feature/virtual-members/Umbraco-OpenIdConnect-Example.Core/CustomMemberSignInManager.cs#L130-L152

    I did it by overriding the IMemberSignInManager:

    https://github.com/jbreuer/Umbraco-OpenIdConnect-Example/blob/feature/virtual-members/Umbraco-OpenIdConnect-Example.Core/Extensions/UmbracoBuilderExtensions.cs#L115-L119

    Roles aren't working yet so that's what I will try next.

    With this experiment ChatGPT was my friend. Got some really helpful tips while working on .NET 7.

    Jeroen

  • Thomas 319 posts 606 karma points c-trib
    Jan 13, 2023 @ 17:12
    Thomas
    0

    Sweet! Will take a look at your code 🙌🏻

  • Jeroen Breuer 4909 posts 12266 karma points MVP 5x admin c-trib
    Nov 04, 2022 @ 12:19
    Jeroen Breuer
    0

    Wow this looks great! Let me know if you can fully integrate it into members. Then I could add it to the Umbraco OpenID Connect example package:

    https://github.com/jbreuer/Umbraco-OpenIdConnect-Example

    Jeroen

  • Jeroen Breuer 4909 posts 12266 karma points MVP 5x admin c-trib
    Mar 03, 2023 @ 08:03
    Jeroen Breuer
    2

    I managed to get virtual members working. It is an experiment though. I don't know if it is wise to use this approach on a live environment.

    You can read the full blog here: https://www.jeroenbreuer.nl/blog/virtual-members-in-umbraco/

    Jeroen

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies