Copied to clipboard

Flag this post as spam?

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


  • commissar 1 post 72 karma points
    Mar 25, 2022 @ 11:52
    commissar
    1

    problem wit external member login + autolinking

    Hi, I am trying to get external login with azure b2c to work in umbraco version: 9.4 (+ uSync package installed)

    I have added openid connect external login to umbraco and added MicrosoftMemberExternalLoginProviderOptions. I return a Challenge from controller action with following code:

    public IActionResult ExternalLogin(string returnUrl)
        {
            return Challenge(
                new AuthenticationProperties
                {
                    RedirectUri = "/blog",
                    Items = { { "returnUrl", returnUrl } }
                }, Constants.Security.MemberExternalAuthenticationTypePrefix + MicrosoftMemberExternalLoginProviderOptions.SchemeName);
        }
    

    ConfigureServices:

            services.ConfigureOptions<MicrosoftMemberExternalLoginProviderOptions>();
            services.AddUmbraco(_env, _config)
                .AddBackOffice()
                .AddWebsite()
                .AddComposers()
                .AddMemberExternalLogins(logins =>
                {
                    logins.AddMemberLogin(
                        memberAuthenticationBuilder =>
                        {
                            memberAuthenticationBuilder.AddOpenIdConnect(
                                memberAuthenticationBuilder.SchemeForMembers(MicrosoftMemberExternalLoginProviderOptions.SchemeName),
                                options =>
                                {
                                    options.Authority = $"https://login.microsoftonline.com/{azureB2CTenant}/v2.0";
                                    options.ClientId = azureB2CClientId;
                                    options.ClientSecret = azureB2CClientSecret;
                                    options.CallbackPath = "/signin-microsoft";
                                    options.Scope.Add(OpenIdConnectScope.Email);
                                    options.ResponseType = OpenIdConnectResponseType.Code; //"code"; 
                                    options.ResponseMode = OpenIdConnectResponseMode.Query;// "query";
                                    options.UsePkce = true;
                                    options.GetClaimsFromUserInfoEndpoint = true;
                                }
                            );
                        });
                })
                .Build();
    

    class MicrosoftMemberExternalLoginProviderOptions is from docs pages:

        public const string SchemeName = "Microsoft";
    
        public void Configure(string name, MemberExternalLoginProviderOptions options)
        {
            if (name != Constants.Security.MemberExternalAuthenticationTypePrefix + SchemeName)
            {
                return;
            }
    
            Configure(options);
        }
    
        public void Configure(MemberExternalLoginProviderOptions options) =>
            options.AutoLinkOptions = new MemberExternalSignInAutoLinkOptions(
                // Must be true for auto-linking to be enabled
                autoLinkExternalAccount: true,
    
                defaultCulture: null,
    
                defaultIsApproved: true,
    
                defaultMemberTypeAlias: "Member",
    
    
                defaultMemberGroups: Array.Empty<string>()
            )
            {
    
                OnAutoLinking = (autoLinkUser, loginInfo) =>
                {
                },
                OnExternalLogin = (user, loginInfo) =>
                {
                    return true; 
                },
            };
    

    Redirect to Microsoft login works, and redirect back to /blogs works as well, but it does not create local account. I thought implementing IConfigureNamedOptions< MemberExternalLoginProviderOptions > will take care of that.

    This are requests from browser: enter image description here

    What am I missing? Thank you.

  • Alin Răuțoiu 27 posts 125 karma points
    Apr 16, 2022 @ 11:14
    Alin Răuțoiu
    0

    I am facing the same problem. The setup pipeline doesn't reach the configuration for MicrosoftMemberExternalLoginProviderOptions. And to be frank, I don't really know why it should reach it. I have the feeling some configuration or convention is missing from the documentation, but I can't figure out what.

  • Lee 1130 posts 3088 karma points
    Jun 08, 2022 @ 11:34
    Lee
    0

    In the IUmbracoBuilder you need to register your MicrosoftMemberExternalLoginProviderOptions class like so.

    builder.Services.ConfigureOptions<MicrosoftMemberExternalLoginProviderOptions>();
    

    Do this before you call .AddMemberExternalLogins(). I made an extension method to do it all

    public static IUmbracoBuilder AddExternalLogins(this IUmbracoBuilder builder, IConfiguration config)
    {
        builder.Services.ConfigureOptions<GoogleMemberExternalLoginProviderOptions>();
        builder.AddMemberExternalLogins(logins =>
        {
            logins.AddMemberLogin(
                memberAuthenticationBuilder =>
                {
                    memberAuthenticationBuilder.AddGoogle(
                        // The scheme must be set with this method to work for the back office
                        memberAuthenticationBuilder.SchemeForMembers(GoogleMemberExternalLoginProviderOptions.SchemeName),
                        options =>
                        {
                            options.ClientId = config.GetValue<string>("MYKEYPATH");
                            options.ClientSecret = config.GetValue<string>("MYKEYPATH");
                            //options.CallbackPath = "";
                        });
                });
        });
        return builder;
    }
    
  • Marcin 3 posts 73 karma points
    Jul 11, 2022 @ 10:44
    Marcin
    0

    But commissar had registered MicrosoftMemberExternalLoginProviderOptions before services.AddUmbraco.

        services.ConfigureOptions<MicrosoftMemberExternalLoginProviderOptions>();
    
    services.AddUmbraco(_env, _config)
    

    What's the difference between calling it in extension method or directly from ConfigureServices?

    I'm asking because I followed documentation and I have similar problem like commissar. Is there any demo I could download and try?

  • Chris 4 posts 95 karma points
    Mar 07, 2024 @ 13:59
    Chris
    0

    Facing the same problem here, using OpenId Connect. Login through MVC button works great, but login through controller seems to be an impossible task. Webapi code for login that redirects to login provider:

        [HttpGet("~/signin")]
            public ActionResult SignIn()
            {
                return new ChallengeResult("UmbracoMembers.OpenIdConnect", new AuthenticationProperties
                {
                    RedirectUri = "/about-us", //test url
                    IsPersistent = true //makes no difference
                }); 
            }
    

    token is accepted, all is 100% well, claims 100%, isauthenticated=true. But it does not trigger OnAutoLinking or OnExternalLogin methods, and cookies not set, so im still not logged in

    using umbraco v13 this site should only be an api using a react frontend, so i need to use an api for login

Please Sign in or register to post replies

Write your reply to:

Draft