Skip to content

Secure an ASP.NET Core Blazor WebAssembly hosted app with Azure Active Directory B2C (Without implicit grant).

License

Notifications You must be signed in to change notification settings

ShadyNagy/b2c-blazor-wasm-31

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Azure B2C Blazor WASM Working with 3.1

Secure an ASP.NET Core Blazor WebAssembly hosted app with Azure Active Directory B2C

Azure B2C not working in Blazor WASM (netstandard2.1) without the implicit grant so that is the solution

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" />

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);

    ...
  }
}