Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unhandled exception rendering component: Failed to construct 'URL': Invalid URL

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"

like image 365
Richard77 Avatar asked Feb 21 '26 13:02

Richard77


2 Answers

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://learn.microsoft.com/en-us/aspnet/core/blazor/security/webassembly/standalone-with-azure-active-directory-b2c?view=aspnetcore-5.0

like image 151
connor-ww Avatar answered Feb 24 '26 12:02

connor-ww


There were 2 real 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

like image 30
Richard77 Avatar answered Feb 24 '26 12:02

Richard77