Configure ADXStudio Portals and CRM portals with Azure AD B2C

Azure Active Directory B2C is a new Azure service that is targeted at helping your organization utilize consumer based identities within your sites and applications. This is a guide covering setting up ADXStudio Portals version 7 and CRM portals v8.1 with Azure AD B2C as an identity provider through configuration.  As well discuss some of the additional customizations that can be made to the ADXStudio Portal v7 MasterPortal code base to further enhance the user experience.

A recent update to Azure AD B2C policies has allowed ADXStudio Portals and CRM portals to work with Azure AD B2C via configuration.  To learn more about the technical change please view Azure AD B2C Now Supports ADXStudio Portal v7.

CRM portals v8.x customization is limited and therefore the user experience that the customizations below outline with Azure AD B2C cannot be completely implemented.  CRM portals v8.2 is expected to support Azure AD B2C natively in the Fall release or in a future monthly update.  All configuration based settings mentioned apply for ADXStudio and CRM portals interchangeably.

Note that while you can configure B2C with CRM portals it is completely unsupported and not recommended by Microsoft. The concern is that when support is added to CRM portals if you were previously using B2C that the implementation might not be compatible with your existing users. Therefore it is advised that you do not configure B2C with CRM portal until it is released directly as a feature of the product. The date for this has also moved to unknown, there was discussion on this coming shortly in 8.2, but that has not be committed to. If you wish to implement Azure AD B2C then you should use the latest version of ADXStudio Portals.

The benefit of using Azure AD B2C is moving the authentication of your users to a common secure global service that be consumed be various different application platforms because of its standard based implementation of OpenID Connect. This allows your users to have a single identity with a common user experience across your portfolio of applications. ADXStudio Portals and CRM portals with its implementation of ASP.NET Identity built on the OWIN Framework supports OpenID Connect since version 7.0.0020 with providers like Azure AD B2C.

To get started you will need to create an Azure AD B2C directory which is completely free up to 50,000 authentications per month. Once you have your Azure AD B2C directory you have the ability to enable various social identity providers like Facebook, Google, LinkedIn, Amazon and Microsoft Account for you users to use. You can also enable users without a social identity account to create local users via email address or username. To learn more about creating a directory and setting up social providers via the guide here.

One of the unique functions of Azure AD B2C is that it has the concept of policies. The policies allow you to segment configurations of your identity service, providing flexibility per application, process or however you decide to use policies.  Policies allow you to customize the branding, as to what might be collected during sign up or the claims that are returned to an application. Based on how the ADXStudio Portal and CRM portals function with identity providers through configuration it is best implemented with a “Sign Up and Sign In” policy instead of separate policies for “Sign In” and “Sign Up”.

For the ADXStudio Portal or CRM portals to consume B2C we will need to list it as an application in the B2C settings.

  1. Navigate to Azure AD B2C tenant and then the settings for the directory in the Azure Portal and select Applications, then Add.
  2. Add your application name, enable Web App / Web API, and enter your reply URL (this must be HTTPS and it only needs to be your ADX portal root URL).
  3. Click the Create button.
  4. Once the application is created, select it and you should see an Application ID. Copy this value and save it.

To configure OpenID Connect for ADXStudio Portal or CRM portals we need to map the functionality of the CreateOptionsFromPolicy method in the GitHub sample for .NET Web App Startup.Auth.cs to the portal site settings documented here for ADXStudio Portals and here for CRM portals.

Adding a new identity provider with ADXStudio Portal or CRM portal is must be done via the CRM GUI, outlined below are the necessary site settings for Azure AD B2C.

The settings all follow the format of Authentication/OpenIdConnect/AzureADB2C/[setting_name]. The text AzureADB2C can be replaced with your desired provider name, the label seen on the portal is configured through the caption setting.

The value is the name of your B2C policy for Sign Up and Sign In.
Sample Value: B2C_1_SuSi

You can obtain this value by selecting your policy and copying the metadata endpoint address at the top of the panel.
Sample Value:


You can obtain this value by navigating to your Metadata Address and copying the value of issuer
Sample Value:


The value is the Application ID that you saved when setting up the application in the previous steps.
Sample Value: e48b78ef-e274-4480-a3d5-621138ae1b47

This value applies to both RedirectUri and PostLogoutRedirectUri. It should be the root URL to your ADX portal.
Sample Value:

This value applies to both RedirectUri and PostLogoutRedirectUri. It should be the root URL to your ADX portal.
Sample Value:

Value: openid

Value: id_token

Value: name

Authentication/OpenIdConnect/AzureADB2C/Caption Optional
This can be set to whatever you would like the button text to read on the Sign In and Register pages of the portal. This value is optional.
Sample Value: Azure AD B2C

Once you have completed all the site settings outlined above associated to your ADX portal website then you should be able to restart the portal application and see the new provider listed under external account.

ADXStudio Portals Sign In:

CRM portals Sign In:

You can now test your registration and sign in flows. The nice thing about the Sign Up and Sign In policy and the portal is it will handle that detection as part of its out of the box configuration. All of the other ADXStudio Portals or CRM portal authentication settings can be used and applied to the site as normal.

The following customizations only applies to ADXStudio Portals.

With the out of box code in ADXStudio Portals login controller the logoff or sign out function will only sign you out from the ADX Portal. To modify this functionality you just need to update the Logoff HTTP GET and POST methods in LoginController.cs. This controller can be found in the MasterPortal code base AreasAccountControllers folder.

// GET: /Login/LogOff
public ActionResult LogOff(string returnUrl)
	if (HttpContext.Request.Url != null && !returnUrl.Contains(HttpContext.Request.Url.Authority))
		returnUrl = $"{HttpContext.Request.Url.Scheme}://{HttpContext.Request.Url.Authority}{returnUrl}";

	var authTypes = AuthenticationManager.GetAuthenticationTypes();

	AuthenticationManager.SignOut(new AuthenticationProperties { RedirectUri = returnUrl }, authTypes.Select(t => t.AuthenticationType).ToArray());
	return Redirect(!string.IsNullOrEmpty(returnUrl) && Url.IsLocalUrl(returnUrl) ? returnUrl : "~/");

The changes here are to ensure that the return URL passed to Azure B2C is a includes the full site URL and not just the relative path. Azure B2C checks this return URL against what was configured in the application settings to ensure it includes the same root URL.   Additional the code to tell ASP.NET Identity OWIN to sign out not only of the portal but also Azure B2C is to modify the SignOut method of the AuthenticationManager to include the authentication types as a parameter. This causes OWIN to process not only the ADX applicaiton cookie but call the associated Azure B2C logoff method which will remove the Azure B2C cookie as well.

Note – you may also modify the ReturnUrl methods in HelpersUrlHelper.cs to output a full qualified URL as the return URL instead of modifying the URL in the LogOff HTTP GET method.

The following is the change to the HTTP POST method, no return URL is needed, just the Authentication Types added to the SignOut parameters.

// POST: /Login/LogOff
public ActionResult LogOff()
	var authTypes = AuthenticationManager.GetAuthenticationTypes();

	AuthenticationManager.SignOut(authTypes.Select(t => t.AuthenticationType).ToArray());
	return Redirect("~/");

The other changes you would be able to make in the code is mapping claims to CRM properties so that the profile is auto populated. Though you may need to consider a more complex implementation so that all CRM modifications of certain attributes are sync’d back to the Azure AD B2C attribute store. If you are interested then check out the Graph API documentation. For a less complex implementation that does not require complex attribute mapping, you could leave contact profile data collection just to CRM/portal and not collect any additional claims on the Azure B2C side.

If you want to at least ensure the email from Azure B2C is mapped to the CRM Contact email address then you can modify the ExternalLoginCallback method in the LoginController.cs and add lines 8 – 11 highlighted in the following code:

var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();

if (loginInfo == null)
	return RedirectToAction("Login");

if (string.IsNullOrEmpty(loginInfo.Email))
	loginInfo.Email = loginInfo.ExternalIdentity.Claims.FirstOrDefault(a => a.Type == "emails")?.Value;

This is necessary due to the AuthenticationManager.GetExternalLoginInfoAsync() method only looking for as the claim type name it would get for email.  Note B2C has been modifying the email claim name recently so you may need to update the Type condition to match what is current.

A last tip, if you plan to only use Azure B2C then it might make sense for your users to skip the portal sign in page and go directly to Azure B2C. This can be done using an out of box site setting Authentication/Registration/LoginButtonAuthenticationType. Simply set this site setting to same value as the site setting Authentication/OpenIdConnect/AzureADB2C/AuthenticationType and the sign in button in headers that utilize the UrlHelper method (default out of box non-liquid based) will forward directly to Azure B2C.

15 thoughts on “Configure ADXStudio Portals and CRM portals with Azure AD B2C

  1. Hi Colin, seeking some clarification. This part of your post: “CRM portals v8.x customization is limited and therefore the user experience that the customizations below outline with Azure AD B2C cannot be completely implemented.”

    Does this just refer to the code customizations that affect the logout experience, or are you saying that B2C won’t work with CRM Portals until v8.2?


    1. Hi Craig, I have actually just recently discussed this with the product team at Microsoft and they are advising that even while it might work it is unsupported and not recommended. They also wanted to clarify that while it is on the roadmap, they are not ready to commit to any date for it. So if you want to use B2C you should currently just stick with ADX v7. I have updated the post above to clarify.


  2. It’s s bummer that they are not supporting Azure AD B2C. I have a huge need for this and I am trying to figure out the best way of solving my problem. We are moving from to Dynamics 365 and have to port over a community to portals. I am having a hard time getting my questions answered as it seems the new Portals that ships with 365 has less functionality of the old portals product.


  3. If you set B2C up with Portals 8 – you can log in *once* with an existing Azure B2C account – and successfully get through and set up your Profile, Contact and External Identities details. When you try and login again however you get that awful “We’re sorry, but something went wrong.” error which you simply cannot track down.

    Do we have any indication as to when B2C will be supported, or when even we’ll have some genuine Portals 8 documentation (as opposed to the 7 documentation with a Search and Replace) will be available . . . ?


    1. Hi Michael, I just validated against v8.2 portals and was able to use B2C with the same login multiple times, not the once. There must be something more going on there or some sort of difference in configuration of the portal or B2C policies.

      Unfortunately I don’t have any new details on a time frame for full support of Azure AD B2C within portals. For documentation, I definitely feel your pain. v8 has been very close to the v7 implementation so the v7 documentation has worked well enough thus far. However with the most recent release there are features that did not exist in v7 and thus no documentation exists. I would suggest you post the idea to the CRM Ideas site –

      If there is a certain documentation topic you were looking for let me know and I will see what I can find out for everyone.


    2. Hi Michael,

      Have you be able to resolve your issue. We are facing same issue and looking for resolution.
      Please share your thoughts.


  4. Hi Colin,

    We have Azure AD B2C authentication implemented for v7. The authentication part works fine but we are just not able to figure out how to map the firstname, lastname and few other custom parameters from claims to CRM form.
    Are we missing any configuration/customization?



  5. Hi Colin, I am currently migrating from Azure ACS to B2C, I’m using ADX Studio Portal 7… with Social authentication (google, facebook, windows live…) I’m wondering if I have to make the same code changes that you explain in this post or if these changes only apply for Azure AD B2C users?
    If so, which changes or settings setup I have to perform in order to make it work with the same social authentication I’ve been using so far?

    Thank you,


  6. Hi Colin,
    I configure the azure b2c authentication in dynamics-365 portal that is in the cloud, the authentication works correctly but the portal does not respect the session time that I configured in the login policy. I need that the portal after 15 minutes of inactivity ask me to relogin in



    1. Hi Viviana, there are 2 portal site settings that control the session expiry on the portal which you need to have match the the B2C session timeout for it all to work properly.

      Session Management for Azure AD B2C:

      Authentication/ApplicationCookie/ExpireTimeSpan – should match your B2C session management policy configuration as a timespan. Within an B2C policy edit, select Token, session, & SSO config, Access & ID token lifetime (minutes) – “The lifetime of the OAuth bear token used to gain access to the protected resource”

      Authentication/ApplicationCookie/SlidingExpiration – set to false


  7. Hi Colin,

    CRM contacts are not created while registering with the portal application through B2C policy. However, there is no error encountered, it redirects to the CRM Portal website profile page but the contact and the related external identity record is not created in CRM.

    Forgot/Change password – on clicking the forgot password link on the signup/signin policy page of B2C an error code is returned which has to be captured and control has to be directed to the password change policy. However, since we do not have the portal code the error cannot be captured and redirected.Similarly, Once the user is logged in, a change password button click should direct the user to the B2C password change policy. How can this be achieved in CRM Portal?



    1. Hi Angeline, I would suggest checking out the Microsoft documentation for configuring B2C with portals to ensure the latest version meets with their suggested configuration. If you are ending up with no contacts then the return back to the portal is likely not working correctly. This could be with the portal configuration or the B2C config so I would just review those both with the latest documentation before proceeding.

      For the forgot password, in the version of this article forgot password was not supported. With the latest documentation and updates to the portal it should now be supported but needs the necessary configuration to function properly. Check out the documentation to ensure it is configured correctly.



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s