Secure an ASP.NET Core Blazor WebAssembly hosted app with Azure Active Directory B2C (Without implicit grant).
1- Create the app Microsoft Documentation
2- Copy file AuthenticationService.js from src folder to your Blazor WASM project (B2CWasm.Client) in wwwroot folder.
3- Change index.html in wwwroot folder from
<script src="_content/Microsoft.Authentication.WebAssembly.Msal/AuthenticationService.js"></script>
to
<script src="AuthenticationService.js"></script>
4- add this package to server
<PackageReference Include="Microsoft.Identity.Web" Version="1.1.0" ></PackageReference>
5- in WeatherForecastController
...
using Microsoft.Identity.Web.Resource;
...
public class WeatherForecastController : ControllerBase
{
...
static readonly string[] scopeRequiredByApi = new string[] { "your scop name" };
...
[HttpGet]
public IEnumerable<WeatherForecast> Get()
{
HttpContext.VerifyUserHasAnyAcceptedScope(scopeRequiredByApi);
...
}
}