Azure / Azure/static-web-apps

Unable to authorize Blazor Webassembly with Static WebApp and Azure API Management

Open
#808 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
No language data
Stars
346
Forks
67
PR merge metrics
No merged PRs in 30d

Description

**Describe the bug**

I have a Standalone Blazor Webassembly that is authenticated with MSAL using the standard `authentication/login` and `authentication\logout` paths

It is deployed on the Azure Static Web Apps free tier right now.

```
// Add Msal
builder.Services.AddMsalAuthentication(options =>
{
builder.Configuration.Bind("LoginAd", options.ProviderOptions.Authentication);

// For linux apps specify issues expliclity
// - https://github.com/dotnet/AspNetCore.Docs/issues/21228
// - https://github.com/dotnet/aspnetcore/issues/25430
// !--https://github.com/dotnet/aspnetcore/issues/38082 --> < PublishTrimmed > false
//
options.ProviderOptions.Authentication.Authority = "https://login.microsoftonline.com/common";

options.ProviderOptions.LoginMode = "redirect";

options.ProviderOptions.DefaultAccessTokenScopes.Add("openid");
options.ProviderOptions.DefaultAccessTokenScopes.Add("offline_access");
options.ProviderOptions.DefaultAccessTokenScopes.Add("profile");
options.ProviderOptions.DefaultAccessTokenScopes.Add("email");

}).AddAccountClaimsPrincipalFactory();
```

I define MSAL config to get the `access_token` with custom scopes and make the API calls through the Azure API Management portal

I want to migrate this app to the Azure Static App's build in authentication and authorization with the following IdPs
- Azure AD
- Azure B2C
- Github

I was reading the [authentication and authorization](https://docs.microsoft.com/en-us/azure/static-web-apps/authentication-authorization?tabs=invitations) documentation and found that this is supported out-of-the box with Azure Paid Tiers

However its not clear for me the following:
1. How would an exiting Blazor Webassembly migrate its authentication paths to use the `/.auth/login/aad`, `/.auth/login/ab2c`, `/.auth/login/github` routes
2. With the new `.auth/login/***` routes how do I specify additional scopes and get the `access_token`
3. How do I use the `access_token` to call the protected web APIs that are hosted on Azure API Management or any other external protected API that authorizes with the `access_token` received from the IdP

**Expected behavior**
A clear and concise description on how to call protected API (Azure Functions, Azure API Management, External API) with access_token and custom scopes.

Visual Studio 2022
Blazor Standalone Webassembly
Azure Static Web APP
Azure API Management

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.