1
votes

I've followed this tutorial line by line. It's teaches how to generate a blazor wasm hosted application with all the code to authenticate with Azure B2C. All I had to do was to replace place the correct values in the right places.

dotnet new blazorwasm -au IndividualB2C --aad-b2c-instance "{AAD B2C INSTANCE}" --api-client-id "{SERVER API APP CLIENT ID}" --app-id-uri "{SERVER API APP ID URI}" --client-id "{CLIENT APP CLIENT ID}" --default-scope "{DEFAULT SCOPE}" --domain "{TENANT DOMAIN}" -ho -o {APP NAME} -ssp "{SIGN UP OR SIGN IN POLICY}"

Unfortunately, when I run it I get this error:

enter image description here

It's hard to tell where the problem is coming from. I googled the error but can't find any documentation on the issue.

Thanks for helping.

Edit

Here's the script that I use to create the Blazor app

dotnet new blazorwasm -au IndividualB2C --aad-b2c-instance "testb2c.onmicrosoft.com" --api-client-id "3b113bda-55d5-47eb-9d8c-5e44375f1341" --app-id-uri "https://testb2c.onmicrosoft.com/testapi" --client-id "3b9fd635-a87f-4899-ad04-9a73fc6f4e21" --default-scope "api.read" --domain "testb2c.onmicrosoft.com" -ho -o BlazorCmdLine -ssp "B2C_1_SignUpIn"

2
It is a guess and not an answer. Maybe you have some "invalid chars" like spaces in your variables? And when the authentications service tries to construct the redirect URL??? for the request, it produces the error? - Just the benno
Your url should look like this: https://{tenant}.onmicrosoft.com/{SERVER API APP ID URI}/scope name. - Carl Zhao
@CarlZhao I just posted my script in the question. Which part of the script should be the way you're describing in your comment? - Richard77
What will happen if you run dotnet new blazorwasm -au IndividualB2C -ho -o BlazorCmdLine? - Allen Wu
@AllenWu, running this command generated only placeholders, which allow to see exactly what was the expectation. Thank you so much - Richard77

2 Answers

3
votes

To anyone who finds themselves in this situation - instead of checking your values and running the command again, open up the appsettings.json file and check the "AzureAdB2C.Authority" value. It should be a valid URL in the format: "{AAD B2C INSTANCE}/{TENANT DOMAIN}/{SIGN UP OR SIGN IN POLICY}"

Example: "https://testb2c.b2clogin.com/testb2c.onmicrosoft.com/B2C_1_SignUpSignIn"

Source: https://docs.microsoft.com/en-us/aspnet/core/blazor/security/webassembly/standalone-with-azure-active-directory-b2c?view=aspnetcore-5.0

2
votes

There were 2 really problems related to the lack of attention.

  1. I used the same value testb2c.onmicrosoft.com for both the {AAD B2C INSTANCE} and the {TENANT DOMAIN}.
  • {AAD B2C INSTANCE} Instance should be https://testb2c.b2clogin.com/
  • {TENANT DOMAIN} domain should be testb2c.onmicrosoft.com
  1. I forgot to add a forward slash at the end of the {AAD B2C INSTANCE} Instance. So I was getting "Authority": "testb2c.onmicrosoft.comtestb2c.onmicrosoft.com/B2C_1_SignUpIn",

Thank you, @just the benno, @Carl Zhao, and @Allen Wu