0
votes

I've been playing with AzureAD B2C using ASP.NET Core 3.1

I've already set up an AzureAD B2C using the project wizard and it's worked well. I now need to retro fit an existing application to use AzureAD B2C.

I've imported the same package from the existing application, ie.. enter image description here

I've setup the appsetting.json file ...

"AzureAdB2C": {
    "Instance": "https://xxx.b2clogin.com/tfp/",
    "ClientId": "xxx-xxx-xxx-xxx-xxx",
    "CallbackPath": "/signin-oidc",
    "Domain": "xxx.onmicrosoft.com",
    "SignUpSignInPolicyId": "B2C_1_SignInRegister",
    "ResetPasswordPolicyId": "B2C_1_PasswordReset",
    "EditProfilePolicyId": "B2C_1_ProfileEdit"
  },

Added the services in ConfigureServices..

services.AddAuthentication(AzureADB2CDefaults.AuthenticationScheme)
                .AddAzureADB2C(options => Configuration.Bind("AzureAdB2C", options));

and added Auth in Configure

            app.UseAuthentication();
            app.UseAuthorization();

For a moment, I see my app shooting over to azure for authentication, but then I get redirected back to https://localhost:xxxx/signin-oidc, with a ERR_CONNECTION_CLOSED

I've missed something somewhere.

1
Solved it, the new project has a different port address - doh!, so the return URL was different.paul1923
Glad to know this issue has been resolved. Can you send an answer so this question can be treated as answered?Allen Wu

1 Answers

0
votes

I fixed this myself, it was an oversight when I set up the new project.

As is typically the case with Visual Studio when using IIS Express to Debug, the new project used a different ssl port. I needed to enter the new port with the Azure AD B2C App Registration.

  1. Note the correct address and port in VS
  2. Go to the Azure Portal, bring up the B2C Overview for the relevant Domain
  3. Click on "App Registrations"
  4. Select the relevant Application
  5. Select the redirect uri's link
  6. Click "Add URI", and enter the correct signin-oidc link, for me, that was https://localhost:44304/signin-oidc

I'll need to remember that when I eventually publish the code. I found that I could enter as many uri's as I needed. Eg, one for DEV, one for QA, one for PROD etc....

enter image description here