I am using Azure static Web app service Static Web App.
Is there a way to disable anonymous access and apply security rules?
I am using Azure static Web app service Static Web App.
Is there a way to disable anonymous access and apply security rules?
Yes - there is way.
A simple example:
If you create a routes.json
file at the root of app's build artifact folder and put something like the following in the file:
{
"routes": [
{
"route": "/login",
"serve": "/.auth/login/aad"
},
{
"route": "/*",
"serve": "/index.html",
"allowedRoles": [
"reader",
"owner",
"contributor"
]
}
],
"platformErrorOverrides": [
{
"errorType": "Unauthenticated",
"statusCode": "302",
"serve": "/login"
}
]
}
This will prompt the user to authenticate using Azure AD and serve the static webpage index.html
only if authentication is successful and the authenticated user has one of the allowedRoles
.
In order to assign a user roles, you have to invite them e.g. by using the
Home > {static web app name} > Role management
tab on portal.azure.com
, and invite a user making sure to set the appropriate role.