Azure ADB2C not working with form authentication together

Abhale, Sankalp 0 Reputation points
2023-01-31T21:20:51.1333333+00:00

Hello,

I am currently working on integration existing app with Azure ADB2C. Previously we were using form authentication. Now we want both form and ADB2C authentication.

I was able to implement ADB2C. But to make it work I had to change Authentication type from "form" to "none".

Due to which existing form authentication is not working, and even after successful login to system, app is redirecting to login page.

Also ADB2C is redirecting to login page even after successful login.

Now I am confused and need help to make both authentication work.

I am giving my startup.cs Configuration function here.

My requirement is both form and ADB2C authentication should work together.

Thank you!

public void Configuration(IAppBuilder app)
        {
            OAuthAuthorizationServerOptions authServerOptions = new OAuthAuthorizationServerOptions()
            {
                AllowInsecureHttp = true,
                TokenEndpointPath = new PathString("/Token"),
                AccessTokenExpireTimeSpan = TimeSpan.FromMinutes(240),
                Provider = new AuthorizationServerProvider(),
                RefreshTokenProvider = new RefreshTokenProvider()
            };


            app.UseOAuthAuthorizationServer(authServerOptions);
            app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions());
            var corsOptions = new Microsoft.Owin.Cors.CorsOptions()
            {
                PolicyProvider = new Microsoft.Owin.Cors.CorsPolicyProvider
                {
                    PolicyResolver = ctx =>
                    {
                        var policy = new CorsPolicy();
                        policy.AllowAnyHeader = true;
                        return Task.FromResult(policy);
                    }
                }
            };
      
            app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);

            app.UseOpenIdConnectAuthentication(
                new OpenIdConnectAuthenticationOptions
                {
                    // Generate the metadata address using the tenant and policy information
                    MetadataAddress = string.Format(Globals.WellKnownMetadata, Globals.Tenant, Globals.DefaultPolicy),

                    // These are standard OpenID Connect parameters, with values pulled from web.config
                    ClientId = Globals.ClientId,
                    RedirectUri = Globals.RedirectUri,
                    PostLogoutRedirectUri = Globals.RedirectUri,
                    
                    
                    // Specify the callbacks for each type of notifications
                    Notifications = new OpenIdConnectAuthenticationNotifications
                    {
                        RedirectToIdentityProvider = OnRedirectToIdentityProvider,
                        AuthorizationCodeReceived = OnAuthorizationCodeReceived,
                        AuthenticationFailed = OnAuthenticationFailed,
                    },

                    // Specify the scope by appending all of the scopes requested into one string (separated by a blank space)
                    Scope = $"openid profile offline_access {Globals.ReadTasksScope} {Globals.WriteTasksScope}",

                    // ASP.NET web host compatible cookie manager
                    CookieManager = new SystemWebCookieManager(),
                    UsePkce = false,
                    RequireHttpsMetadata = false,
                }
            );

            app.UseStageMarker(PipelineStage.Authenticate);
            app.UseCors(corsOptions);
            IdentityModelEventSource.ShowPII = true;
            RegisterSignalR(app);

            GlobalConfiguration.Configure(WebApiConfig.Register);
            GlobalConfiguration.Configuration.EnsureInitialized();
        }
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
19,447 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Shweta Mathur 27,381 Reputation points Microsoft Employee
    2023-02-02T13:33:18.3066667+00:00

    Hi @Abhale, Sankalp ,

    Thanks for reaching out.

    I understand you are trying to configure multiple authentication scheme to authenticate users from Azure AD B2C and form-based authentication.

    The available authentication schemes provided by Micrsoft Identity are: 'Cookies', 'OpenIdConnect', and 'Bearer' which you can configured as mentioned here - https://github.com/AzureAD/microsoft-identity-web/wiki/Multiple-Authentication-Schemes

    There is similar thread in SO as well https://stackoverflow.com/questions/67095481/asp-net-mixed-authentication-azure-ad-forms

    Hope this will help.

    Thanks,

    Shweta


    Please remember to "Accept Answer" if answer helped you.

    0 comments No comments

  2. Abhale, Sankalp 0 Reputation points
    2023-02-06T17:15:14.47+00:00

    Hey,

    No its not helping to resolve my issue

    0 comments No comments

  3. Abhale, Sankalp 0 Reputation points
    2023-02-07T14:22:03.9933333+00:00

    @Shweta Mathur : Thanks for above links. The current challenge that I am facing is, I am not able to get the claims in current Principal after login from adb2c. but same is working when I use form authentication with authentication type as none

    0 comments No comments