Using Microsoft.Identity.Web templates to connect to Azure AD B2C via VS 2019

Rory Braybrook
The new control plane
Nov 17, 2020

This complements a previous article that used the command line only.

This does the same thing but using VS 2019 Version 16.8.1.

I also have .NET 5.0 installed as well as the 1.3.0 version of Microsoft.Identity.Web.

Create a B2C app. registration with:

  • Accounts in any identity provider or organizational directory (for authenticating users with user flows)
  • Allow access and ID tokens
  • A redirect URI of “https://localhost:12345/signin-oidc
  • Note the client and tenant id

You also need a V2 SUSI policy.

Open VS 2019.

Open View / Terminal.

Navigate to a new empty folder via “cd path to folder”.

Run:

dotnet new mvc2
--framework net5.0
--auth IndividualB2C
--domain tenant.onmicrosoft.com
--tenant-id 65f7...2316
--client-id a2dc...b9c9
--susi-policy-id B2C_1_SUSI_V2

Where the id’s are as above, the tenant name is the name of your B2C tenant and the policy name is the one you created.

This will create the project files.

Now use VS to open the .csproj file in that folder via “File / Open Project/Solution”.

Build the project in VS (F6).

Open Properties / launchSettings.json

Note the SSL port e.g.:

“sslPort”: 44374

Change the redirect URI in the app. registration to e.g.

https://localhost:44374/signin-oidc

Run the VS project (F5).

You should then see the B2C login screen and be able to authenticate with a local account.

All good!

--

--

The new control plane
The new control plane

Published in The new control plane

“Identity is the new control plane”. Articles around Microsoft Identity, Auth0 and identityserver. Click the “Archive” link at the bottom for more posts.

Rory Braybrook
Rory Braybrook

Written by Rory Braybrook

NZ Microsoft Identity dude and MVP. Azure AD/B2C/ADFS/Auth0/identityserver. StackOverflow: https://bit.ly/2XU4yvJ Presentations: http://bit.ly/334ZPt5