Copied to clipboard

Flag this post as spam?

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


  • Matt 358 posts 840 karma points
    Jul 10, 2019 @ 06:47
    Matt
    0

    AD for backend

    Hi,

    Is there a detail tutorial of how to get AD to work for backend login?

    There is this URL;

    https://our.umbraco.com/documentation/Reference/Security/#authenticating-with-active-directory-credentials

    but i was hopeing someone would of done something a little more detailed for the noobs out there :)

    Thanks

  • Sibren 40 posts 212 karma points c-trib
    Jul 16, 2019 @ 08:02
    Sibren
    0

    8.0 or 8.1?

    This code: https://our.umbraco.com/documentation/Reference/Security/authenticate-with-AD works for 8.0. For 8.1, you need to add Mapper, after membershipProvider,. Then make sure you edit the web.config. Change it to: <add key="owin:appStartup" value="ActiveDirectoryStartup" /> where ActiveDirectoryStartup is the name of your OWIN start.

    I created a custom ActiveDirectoryPasswordChecker, which also creates the user if it doesn't exist, but that might be over the top.

    Full code for 8.1:

    [assembly: OwinStartup("ActiveDirectoryStartup", typeof(ActiveDirectoryStartup))]
    

    namespace ActiveDirectoryLogin { public class ActiveDirectoryStartup : UmbracoDefaultOwinStartup { public override void Configuration(IAppBuilder app) { //ensure the default options are configured base.Configuration(app);

            // active directory authentication
            ConfigureBackofficeActiveDirectoryPasswords(app);
        }
    
        private void ConfigureBackofficeActiveDirectoryPasswords(IAppBuilder app)
        {
            // https://our.umbraco.com/forum/extending-umbraco-and-using-the-api/96654-applicationcontextcurrent-in-umbraco-8#comment-308432
            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,
                        Mapper,
                        UmbracoSettings.Content, GlobalSettings);
                    //Set your own custom IBackOfficeUserPasswordChecker   
                    userManager.BackOfficeUserPasswordChecker = new ActiveDirectoryPasswordChecker();
                    return userManager;
                });
        }
    }
    

    }

    (replace ActiveDirectoryPasswordChecker() with ActiveDirectoryBackOfficeUserPasswordChecker() for the default, or create the ActiveDirectoryPasswordChecker() to create your own)

Please Sign in or register to post replies

Write your reply to:

Draft