Azure / Azure/static-web-apps

Custom roles via "rolesSource" with API as backend results in 404: Not Found

Open
#1,105 3 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

According to the documentation [here](https://learn.microsoft.com/en-us/azure/static-web-apps/authentication-custom?tabs=openid-connect%2Cfunction) we can add custom roles within "auth" section of the configuration file to reference an API which returns the user roles in json schema.

My SWA setup is with the /api pointing to the API Management service and have a corresponding api at `/api/account/get-roles` which returns the following payload:

```
{"roles":["authenticated"]}
```

This endpoint works via the swa full url such as `https://mywebsite-url.com/api/account/get-roles`.
However as soon as I add that path `/api/account/get-roles` under the "auth" settings that url is returning a static html page with 404: Not found as content

![image](https://user-images.githubusercontent.com/112731230/224826267-689f359e-dc92-48ee-9f4e-e4fb91b9a9fd.png)

![image](https://user-images.githubusercontent.com/112731230/224826101-b5651d1a-7c82-4eaa-af12-a83bd5b120df.png)

**To Reproduce**
Steps to reproduce the behavior:
1. Set up a SWA app with custom openid provider
2. Setup the SWA to point to API Management
3. Setup a mock API that returns a custom role
4. Verify custom role API is proxied properly via SWA domain
5. Login to the SWA app
6. Add the following code to the staticwebapp.config.json pointing to your custom role mock API
```{
"auth": {
"rolesSource": "/api/GetRoles",
"identityProviders": {
// ...
}
}
}
```
7. Try to login to the SWA app again
Expected result:

App should run and the backend call to custom role should be successful to get the roles back from api

Actual result:

App loads and the API to the custom roles API returns 404 error causing the rest of the js execution chain to fail.

**Expected behavior**
New roles to be used from the custom APIM api

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.