Integrating AD B2C to MVC Core app

Hrvoje Hudo 41 Reputation points
2021-07-28T22:11:50.29+00:00

I am starting a new (MVC Core) project that needs to have login/register/edit/reset pass account functionality and wanted to use AD B2C.
But can't understand and configure it properly.
I followed tutorials on Docs, created AD Tenant, created new MVC Core app with Ms Identity Platform for auth, configured it to use AD, and when I start it, it offers login immediatelly, I can login with my personal MSA but not with one user I created in AD B2C!

Why I can't login with user from AD?
Where's Edit profile, Reset pass and other pages? I created 2 user flows in B2C - sign in/out, edit profile. But how to use that from my app?
When I test flow - sign in for example, UI is completely different from the sign in UI i get when i start my app. Why is that? Shouldn't my app use that signin user flow with its UI template?
Is there some full sample that covers basic account create/edit functionality with B2C and MVC Core 3 / 5?

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,561 questions
Microsoft Entra External ID
Microsoft Entra External ID
A modern identity solution for securing access to customer, citizen and partner-facing apps and services. It is the converged platform of Azure AD External Identities B2B and B2C. Replaces Azure Active Directory External Identities.
2,886 questions
0 comments No comments
{count} votes

Accepted answer
  1. AmanpreetSingh-MSFT 56,616 Reputation points
    2021-07-30T07:42:27.563+00:00

    Hi @Hrvoje Hudo · Thank you for reaching out.

    Please find my comments inline:

    1. Why I can't login with user from AD?
      What is the error/behavior you encounter? If you have created the user using Azure Portal, it gets created with temporary password. If you have not reset the password to assign a permanent password, make sure the checkbox for Self-service password reset is checked in the properties of the User Flow.
    2. Where's Edit profile, Reset pass and other pages? I created 2 user flows in B2C - sign in/out, edit profile. But how to use that from my app?
      You can add links to profile editing and password reset user flow to the navbar by adding below list item in the _Layout.cshtml file as shown below: <li class="nav-item">
      <a class="nav-link text-dark" asp-area="MicrosoftIdentity" asp-controller="Account" asp-action="EditProfile">Edit Profile</a>
      </li>
      <li class="nav-item">
      <a class="nav-link text-dark" asp-area="MicrosoftIdentity" asp-controller="Account" asp-action="ResetPassword">Reset Password</a>
      </li>
    3. When I test flow - sign in for example, UI is completely different from the sign in UI i get when i start my app. Why is that? Shouldn't my app use that signin user flow with its UI template?
      Not sure how you have configured the UI, but If you have provided URL to your custom HTML template in Custom Page URI field under Page Layout blade of the user flow, it should always use that.
    4. Is there some full sample that covers basic account create/edit functionality with B2C and MVC Core 3 / 5?
      Please refer to below document that I have created with step by step instructions for this purpose:
      https://github.com/amanmcse/Document/blob/main/AzureADB2C_AuthApp.md
      Note: Under Create your ASP.NET project section, use dotnet new mvc instead of dotnet new webapp.

    Please "Accept the answer" if the information helped you. This will help us and others in the community as well.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.