Azure / Azure/static-web-apps

Authentication issues in Angular app with Static Web Apps and MSAL

Open
#1,522 0 comments 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**

After successful login through SWA, MSAL doesn't detect any authenticated accounts, causing a redirect loop.

**Setup**

Angular application using the latest MSAL version
Deployed on Azure Static Web Apps (SWA) with Entra ID authentication
Route guard checks MSAL for user authentication
If not authenticated, redirects to SWA auth route

**Expected behavior**
User authenticates with SWA and is able to be used by MSAL when Angular application auth runs.

**SWA auth config**

"identityProviders": {
"azureActiveDirectory": {
"registration": {
"openIdIssuer": "https://login.microsoftonline.com/#{PLACEHOLDER_ADTENANTID}#/v2.0",
"clientIdSettingName": "AZURE_CLIENT_ID",
"clientSecretSettingName": "AZURE_CLIENT_SECRET"
}
}
}

**MSAL config**
Same Tenant and Client Id

**Route guard(simplified) causing the loop**
```
if (this.msal.instance.getAccounts().length > 0)
return 'AUTHENTICATED'

return redirectTo(SWAURL + '/.auth/login/aad')
```

**Additional context**
The application should be able to run and authenticate locally using only Angular, without relying on Azure Static Web Apps or its CLI.

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.