Copied to clipboard

Flag this post as spam?

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


  • Sekou Terry 22 posts 94 karma points
    Apr 04, 2019 @ 00:57
    Sekou Terry
    0

    ApplicationContext.current in Umbraco 8

    I'm working on adding Active Directory back office login (and eventually AD access for protected pages) to an Umbraco 8 website. I've been using https://our.umbraco.com/documentation/Reference/Security/authenticate-with-AD as a starting point. The ConfigureUserManagerForUmbracoBackOffice function uses an ApplicationContext object but it doesn't seem to be a part of the Umbraco.Core namespace in Umbraco 8. I saw another article that suggested the singleton ApplicationContext.current was to be avoided. Has it been moved, or am I making a mistake? Thanks in advance!

  • Corné Strijkert 80 posts 456 karma points c-trib
    Apr 08, 2019 @ 17:52
    Corné Strijkert
    7

    In Umbraco 8 you can access the Umbraco services with:

    Umbraco.Core.Composing.Current
    
  • Sekou Terry 22 posts 94 karma points
    Apr 10, 2019 @ 21:31
    Sekou Terry
    0

    Thank you! Just looking to clarify. When I implement ConfigureUserManagerForUmbracoBackOffice like this:

              app.ConfigureUserManagerForUmbracoBackOffice<BackOfficeUserManager, BackOfficeIdentityUser>(
                    applicationContext,
                (options, context) =>
                {
                    var membershipProvider = Umbraco.Core.Security.MembershipProviderExtensions.GetUsersMembershipProvider().AsUmbracoMembershipProvider();
                    var settingContent = Umbraco.Core.Configuration.UmbracoConfig.For.UmbracoSettings().Content;
                    var userManager = BackOfficeUserManager.Create(
                        options,
                        Umbraco.Core.Composing.Current.Services.UserService, 
                        Umbraco.Core.Composing.Current.Services.EntityService,
                        Umbraco.Core.Composing.Current.Services.ExternalLoginService,
                        membershipProvider,
                settingContent
                    );
                    userManager.BackOfficeUserPasswordChecker = new ActiveDirectoryBackOfficeUserPasswordChecker();
                    return userManager;
                });
    

    I get an error about not finding a correctly formed userManager argument. I'm also curious about the applicationContext as an argument since I wouldn't be getting it from ApplicationContext.Current.

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Apr 11, 2019 @ 06:47
    Dave Woestenborghs
    0

    Hi Sekou,

    The signature of this method has changed in V8.

    Here is a example from core : https://github.com/umbraco/Umbraco-CMS/blob/d0b9fb7d6fdbee3116ae98e056dd4ac108a28d4f/src/Umbraco.Web/Security/AppBuilderExtensions.cs

    Dave

  • Anders Brohus 194 posts 475 karma points
    Jun 13, 2019 @ 09:24
    Anders Brohus
    0

    Hi Dave,

    I'm not quite sure what i should be looking at? :)

    Currently getting this error which looks alot like the one above,

    There is no argument given that corresponds to the required formal parameter 'userManager' of 'AppBuilderExtensions.ConfigureUserManagerForUmbracoBackOffice<TManager, TUser>(IAppBuilder, IRuntimeState, IGlobalSettings, Func<IdentityFactoryOptions<TManager>, IOwinContext, TManager>)'
    
  • Sekou Terry 22 posts 94 karma points
    Apr 17, 2019 @ 23:38
    Sekou Terry
    0

    Hey Dave and Corné, I decided to go a different route and used Azure Active Directory login with the IdentityExtensions package. Thanks!

  • Anders Brohus 194 posts 475 karma points
    Jun 13, 2019 @ 11:20
    Anders Brohus
    0

    We found a solution :)

    For reference use :)

    var applicationContext = Umbraco.Core.Composing.Current.Services;
            IGlobalSettings GlobalSettings = Umbraco.Core.Composing.Current.Configs.Global();
            IUmbracoSettingsSection UmbracoSettings = Umbraco.Core.Composing.Current.Configs.Settings();
    
            app.ConfigureUserManagerForUmbracoBackOffice<BackOfficeUserManager, BackOfficeIdentityUser>(Umbraco.Web.Composing.Current.RuntimeState, GlobalSettings,
                (options, context) =>
                {
                    var membershipProvider = MembershipProviderExtensions.GetUsersMembershipProvider().AsUmbracoMembershipProvider();
                    var userManager = BackOfficeUserManager.Create(options,
                        applicationContext.UserService,
                        applicationContext.MemberTypeService,
                        applicationContext.EntityService,
                        applicationContext.ExternalLoginService,
                        membershipProvider, UmbracoSettings.Content, GlobalSettings);
                    //Set your own custom IBackOfficeUserPasswordChecker   
                    userManager.BackOfficeUserPasswordChecker = new customPasswordChecker();
                    return userManager;
                });
    
  • fatmazayed 41 posts 123 karma points
    Feb 14, 2024 @ 22:16
    fatmazayed
    0

    iam using this mway in umbraco 13 guid

  • 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