Issue with azure ad authentication #1720
-
I have setup app using azure static web app and azure sql and i am using azure ad for authentication , locally it works fine with dab cli but when i deploy app to azure then i am getting error
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 10 replies
-
Hi @mshafiqmk , When using DAB with Static Web Apps (Database Connections feature), DAB configuration (for Static Web Apps, this file may be named "authentication": {
"provider": "StaticWebApps"
} From Static Web Apps, you can then configure authentication providers like Azure AD. Step by step found here: https://learn.microsoft.com/azure/static-web-apps/authentication-authorization For convenience, these were the steps I had used to create my own working SWA+DAB environment. The following changes should be made in your Static Web Apps config file
"auth": {
"identityProviders": {
"azureActiveDirectory": {
"registration": {
"openIdIssuer": "https://login.microsoftonline.com/<TENANT_ID_REPLACE_THIS>/v2.0",
"clientIdSettingName": "AZURE_CLIENT_ID",
"clientSecretSettingName": "AZURE_CLIENT_SECRET"
}
}
}
}
{
"route": "/data-api/*",
"allowedRoles": ["anonymous","authenticated"]
}
{
"route": "/data-api/*",
"allowedRoles": ["anonymous","authenticated", "samplerole"]
} Example config file (For reference only): {
"routes": [
{
"route": "/authenticated/*",
"allowedRoles": [
"authenticated"
]
},
{
"route": "/data-api/*",
"allowedRoles": [
"anonymous",
"authenticated"
]
}
],
"auth": {
"identityProviders": {
"azureActiveDirectory": {
"registration": {
"openIdIssuer": "https://login.microsoftonline.com/<TENANT_ID_REPLACE_THIS>/v2.0",
"clientIdSettingName": "AZURE_CLIENT_ID",
"clientSecretSettingName": "AZURE_CLIENT_SECRET"
}
}
}
}
} |
Beta Was this translation helpful? Give feedback.
-
I am encountering this issue using the free tier of Azure Static Web Apps. The solution identified in this thread by @seantleonard evidently applies only to the Standard tier of Static Web Apps which supports custom authentication utilizing the Is authenticated, role-based access to the database supported when using the free tier of Static Web Apps? If so, what is the equivalent solution for the free tier? |
Beta Was this translation helpful? Give feedback.
-
I am encountering the same issue. When I am using the SWA CLI emulator locally I can only authenticate my request by using this authentication to my dab.config.json file.:
If I instead change it to
it is not able to authenticate my request. When I am trying to follow the accepted answer from @seantleonard by adding the routing to my staticwebapp.config.json file I am not able to authenticate either in the emulator or in my preview environment. I have setup my authentication following this guide: https://learn.microsoft.com/en-us/azure/data-api-builder/authentication-azure-ad If I set the role to anonymous it is working both in my SWA CLI and in my SWA preview environment. This is how my staticwebapp.config.json looks like:
And this is my dab.config.json:
All the different roles in both the dab.config.json and swa.config.json is for testing purposes. I am also considering to change the hosting to Container Apps/Instances instead but would prefer to have it working through SWA. |
Beta Was this translation helpful? Give feedback.
Hi @mshafiqmk ,
When using DAB with Static Web Apps (Database Connections feature), DAB configuration (for Static Web Apps, this file may be named
staticwebapp.database.config.json
) and DAB's config should use the following authentication config per this doc snippet:From Static Web Apps, you can then configure authentication providers like Azure AD. Step by step found here: https://learn.microsoft.com/azure/static-web-apps/authentication-authorization
For convenience, these were the steps I had used to create my own working SWA+DAB environment.
The following changes should be made in your Static Web Apps config file
staticwebapp.conf…