Copied to clipboard

Flag this post as spam?

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

  • kevinewig 2 posts 72 karma points
    Nov 05, 2021 @ 03:07

    Backoffice Azure AD Login: Unable to Compile Startup.cs


    I am trying to have users log into the Umbraco 9 BackOffice with Azure AD. I tried to follow the post () however I have been unable to compile the code there.

    This is the error I am getting:

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

    It seems to have problems compiling auth.SchemeForBackOffice

    I have .Net Core 5.

    The libraries in my project are:

    • Microsoft.AspNetCore.Authentication.Abstractions, Version="2.2.0"
    • Microsoft.AspNetCore.Authentication.AzureAD.UI" Version="5.0.11
    • Microsoft.AspNetCore.Authentication.Core" Version="2.2.0"
    • Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="5.0.11"
    • Microsoft.ICU.ICU4C.Runtime" Version=""
    • Microsoft.Identity.Web" Version="1.19.0"

    My Startup.cs file looks like this:

    using System;
    using Microsoft.AspNetCore.Builder;
    using Microsoft.AspNetCore.Hosting;
    using Microsoft.Extensions.Configuration;
    using Microsoft.Extensions.DependencyInjection;
    using Microsoft.Extensions.Hosting;
    using Umbraco.Cms.Core.DependencyInjection;
    using Umbraco.Cms.Web.BackOffice.Security;
    using Umbraco.Extensions;
    using Microsoft.Identity.Web;
    namespace MyProject
        public class Startup
            private readonly IWebHostEnvironment _env;
            private readonly IConfiguration _config;
            /// <summary>
            /// Initializes a new instance of the <see cref="Startup" /> class.
            /// </summary>
            /// <param name="webHostEnvironment">The web hosting environment.</param>
            /// <param name="config">The configuration.</param>
            /// <remarks>
            /// Only a few services are possible to be injected here
            /// </remarks>
            public Startup(IWebHostEnvironment webHostEnvironment, IConfiguration config)
                _env = webHostEnvironment ?? throw new ArgumentNullException(nameof(webHostEnvironment));
                _config = config ?? throw new ArgumentNullException(nameof(config));
            /// <summary>
            /// Configures the services.
            /// </summary>
            /// <param name="services">The services.</param>
            /// <remarks>
            /// This method gets called by the runtime. Use this method to add services to the container.
            /// For more information on how to configure your application, visit
            /// </remarks>
            public void ConfigureServices(IServiceCollection services)
    #pragma warning disable IDE0022 // Use expression body for methods
                services.AddUmbraco(_env, _config)
                    .AddBackOfficeExternalLogins(extLoginBuilder =>
                        var extLoginOpts = new ExternalSignInAutoLinkOptions(
                            autoLinkExternalAccount: true,
                            defaultUserGroups: new[] { "admin" },
                            defaultCulture: "en-US",
                            allowManualLinking: true)
                            OnExternalLogin = (user, loginInfo) =>
                                return true;
                        var loginProviderOptions = new BackOfficeExternalLoginProviderOptions(
                            autoRedirectLoginToExternalProvider: false);
                            auth =>
                                var azAdConfig = _config.GetSection("AzureAd");
                    .AddMicrosoftIdentityWebApp(options =>
                                    options.CallbackPath = "/umbraco-signin-oidc";
                                    options.Instance = "";
                                    options.TenantId = azAdConfig["TenantId"];
                                    options.ClientId = azAdConfig["ClientId"];
                                    options.SignedOutRedirectUri = "/umbraco";
                    //options.ClaimActions.MapJsonKey(ClaimTypes.Email, ClaimConstants.PreferredUserName);
                    // Preferred over IClaimsTransformation which runs for every AuthenticateAsync
                    options.Events.OnTokenValidated = ctx =>
                                        var username = ctx.Principal?.Claims.FirstOrDefault(c => c.Type == ClaimConstants.PreferredUserName);
                                        if (username != null && ctx.Principal?.Identity is ClaimsIdentity claimsIdentity)
                                                new Claim(
                                        return Task.CompletedTask;
                    openIdConnectScheme: auth.SchemeForBackOffice(Constants.AzureAd),
                    cookieScheme: "Fake")
    #pragma warning restore IDE0022 // Use expression body for methods
            /// <summary>
            /// Configures the application.
            /// </summary>
            /// <param name="app">The application builder.</param>
            /// <param name="env">The web hosting environment.</param>
            public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
                if (env.IsDevelopment())
                    .WithMiddleware(u =>
                    .WithEndpoints(u =>

    I would appreciate any help anyone could provide for me.

    Thank you!

    Regards, Kevin

  • Thomas 255 posts 525 karma points c-trib
    19 days ago

    Did you get it to work?

  • kevinewig 2 posts 72 karma points
    1 week ago

    No. I was not able to get it to work.

    I need help authenticating Umbraco 9 with Azure AD. Any examples would be greatly appreciated.

Please Sign in or register to post replies

Write your reply to: