Skip to content

Commit 43a5ffd

Browse files
authored
Fix SWA linked backend silently re-enabling Easy Auth on API App Service (#249)
1 parent fde3aef commit 43a5ffd

3 files changed

Lines changed: 31 additions & 0 deletions

File tree

infra/main.bicep

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ module staticwebapp 'modules/staticwebapp.bicep' = {
176176
customDomainName: swaCustomDomainName
177177
enableCustomDomain: enableSwaCustomDomain
178178
apiAppResourceId: compute.outputs.apiAppId
179+
apiAppName: apiAppName
179180
}
180181
}
181182

infra/modules/staticwebapp.bicep

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ param enableCustomDomain bool = false
1111
@description('Resource ID of the API App Service to link as a backend. SWA will proxy /api/* requests to it.')
1212
param apiAppResourceId string
1313

14+
@description('Name of the API App Service. Used to reset Easy Auth after SWA linking re-enables it.')
15+
param apiAppName string
16+
1417
var tags = {
1518
environment: environment
1619
project: 'XenobiaSoftSudoku'
@@ -36,6 +39,27 @@ resource staticWebAppLinkedBackend 'Microsoft.Web/staticSites/linkedBackends@202
3639
}
3740
}
3841

42+
// SWA's linkedBackend creation automatically re-enables Easy Auth on the API App Service
43+
// and configures it to only accept SWA-issued tokens. Reset it here (after linking) so
44+
// direct callers (e.g. the Blazor App Service) are not blocked by the injected auth layer.
45+
resource existingApiApp 'Microsoft.Web/sites@2023-12-01' existing = {
46+
name: apiAppName
47+
}
48+
49+
resource apiAuthDisabledAfterLinking 'Microsoft.Web/sites/config@2023-12-01' = {
50+
parent: existingApiApp
51+
name: 'authsettingsV2'
52+
dependsOn: [staticWebAppLinkedBackend]
53+
properties: {
54+
globalValidation: {
55+
requireAuthentication: false
56+
}
57+
platform: {
58+
enabled: false
59+
}
60+
}
61+
}
62+
3963
// Binds the custom domain to the SWA production environment.
4064
// Azure SWA automatically provisions a free managed SSL certificate —
4165
// no separate cert or SSL module required.

src/frontend/Sudoku.React/public/staticwebapp.config.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
{
2+
"routes": [
3+
{
4+
"route": "/api/*",
5+
"allowedRoles": ["anonymous"]
6+
}
7+
],
28
"navigationFallback": {
39
"rewrite": "/index.html",
410
"exclude": ["/images/*", "/css/*", "/js/*", "*.{png,jpg,svg,ico,json,woff,woff2,ttf,eot}", "/api/*"]

0 commit comments

Comments
 (0)