Skip to content

Commit 2940d39

Browse files
Update blog 5.8: use real Azure/GitHub Pages URLs, fix CORS step, add GitHub Pages to identityserverdata.json
1 parent 4f8a5e6 commit 2940d39

1 file changed

Lines changed: 28 additions & 20 deletions

File tree

blogs/series-5-devops-data/5.8-azure-post-deployment-config.md

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ This article is part of the **AngularNetTutorial** series. The full-stack tutori
3131
**Before following this article, you should have:**
3232

3333
* **Article 5.6 complete** — IdentityServer deployed at `https://app-talent-ids-dev.azurewebsites.net`
34-
* **Article 5.7 complete** — Angular deployed at the Static Web App URL (e.g., `https://agreeable-desert-01234567.azurestaticapps.net`)
34+
* **Article 5.7 complete** — Angular deployed at the Static Web App URL (e.g., `https://mango-flower-0ced4011e.4.azurestaticapps.net`)
3535
* **The three Azure URLs** — retrieve them:
3636

3737
```bash
@@ -58,7 +58,7 @@ az staticwebapp show \
5858

5959
## 🎯 The Problem
6060

61-
OAuth 2.0 authorization codes and tokens can only flow to URLs that are explicitly registered in the authorization server (IdentityServer). If the Angular application running at `https://agreeable-desert-01234567.azurestaticapps.net` sends an authorization request asking IdentityServer to redirect the browser back to that URL, IdentityServer checks its registered `RedirectUris` for the `TalentManagement` client. If the production URL isn't there, IdentityServer rejects the request immediately with `invalid_redirect_uri`.
61+
OAuth 2.0 authorization codes and tokens can only flow to URLs that are explicitly registered in the authorization server (IdentityServer). If the Angular application running at `https://mango-flower-0ced4011e.4.azurestaticapps.net` sends an authorization request asking IdentityServer to redirect the browser back to that URL, IdentityServer checks its registered `RedirectUris` for the `TalentManagement` client. If the production URL isn't there, IdentityServer rejects the request immediately with `invalid_redirect_uri`.
6262

6363
Similarly, the API's CORS policy controls which origins can call the API from a browser. If the Angular app's domain is not in the allowed origins list, the browser blocks the API response before Angular can read it — even though the API returned HTTP 200.
6464

@@ -123,7 +123,7 @@ Open `TokenService/Duende-IdentityServer/shared/identityserverdata.json`. Find t
123123
}
124124
```
125125

126-
Add the production Azure URLs to each list. Replace `https://agreeable-desert-01234567.azurestaticapps.net` with your actual Static Web App URL:
126+
Add the production Azure URLs to each list. Replace `https://mango-flower-0ced4011e.4.azurestaticapps.net` with your actual Static Web App URL:
127127

128128
```json
129129
{
@@ -136,19 +136,24 @@ Add the production Azure URLs to each list. Replace `https://agreeable-desert-01
136136
"https://localhost:4200/silent-refresh.html",
137137
"http://localhost:4200/callback",
138138
"https://localhost:4200/callback",
139-
"https://agreeable-desert-01234567.azurestaticapps.net",
140-
"https://agreeable-desert-01234567.azurestaticapps.net/silent-refresh.html",
141-
"https://agreeable-desert-01234567.azurestaticapps.net/callback"
139+
"https://mango-flower-0ced4011e.4.azurestaticapps.net",
140+
"https://mango-flower-0ced4011e.4.azurestaticapps.net/silent-refresh.html",
141+
"https://mango-flower-0ced4011e.4.azurestaticapps.net/callback",
142+
"https://workcontrolgit.github.io/AngularNetTutorial",
143+
"https://workcontrolgit.github.io/AngularNetTutorial/silent-refresh.html",
144+
"https://workcontrolgit.github.io/AngularNetTutorial/callback"
142145
],
143146
"PostLogoutRedirectUris": [
144147
"http://localhost:4200",
145148
"https://localhost:4200",
146-
"https://agreeable-desert-01234567.azurestaticapps.net"
149+
"https://mango-flower-0ced4011e.4.azurestaticapps.net",
150+
"https://workcontrolgit.github.io/AngularNetTutorial"
147151
],
148152
"AllowedCorsOrigins": [
149153
"http://localhost:4200",
150154
"https://localhost:4200",
151-
"https://agreeable-desert-01234567.azurestaticapps.net"
155+
"https://mango-flower-0ced4011e.4.azurestaticapps.net",
156+
"https://workcontrolgit.github.io"
152157
]
153158
}
154159
```
@@ -170,23 +175,20 @@ For this tutorial, Option A (commit and push) is preferred — the source file r
170175

171176
### Step 4: Update API CORS Settings
172177

173-
The API allows CORS origins configured in `appsettings.json`. Locate the CORS section:
174-
175-
```bash
176-
grep -n "CorsOrigins\|AllowedOrigins\|Cors" \
177-
ApiResources/TalentManagement-API/TalentManagementAPI.WebApi/appsettings.json
178-
```
179-
180-
Add the Static Web App URL to the allowed origins, then push the change or set it as an App Service setting:
178+
The API allows CORS origins configured via App Service settings using the `Cors__AllowedOrigins__` array pattern. Two origins are needed — the Azure Static Web App and GitHub Pages:
181179

182180
```bash
183181
az webapp config appsettings set \
184182
--resource-group rg-talent-dev \
185183
--name app-talent-api-dev \
186-
--settings "CorsOrigins=https://agreeable-desert-01234567.azurestaticapps.net"
184+
--settings \
185+
"Cors__AllowedOrigins__0=https://mango-flower-0ced4011e.4.azurestaticapps.net" \
186+
"Cors__AllowedOrigins__1=https://workcontrolgit.github.io"
187187
```
188188

189-
The API middleware reads this setting at startup and adds the origin to the allowed list.
189+
**Note:** Replace `https://mango-flower-0ced4011e.4.azurestaticapps.net` with your actual Static Web App URL. The GitHub Pages origin is the host only — no path suffix. This is handled automatically by the `deploy-api.yml` workflow on every deployment, so this manual step is only needed if you are configuring the API outside of a workflow run.
190+
191+
The API's CORS middleware reads `Cors:AllowedOrigins` from `IConfiguration` at startup. The `__` double-underscore in the setting name maps to the `:` separator, and the `__0` / `__1` suffixes create an array in .NET configuration.
190192

191193
### Step 5: Validate Each Layer in Order
192194

@@ -240,12 +242,18 @@ After completing Steps 1–4, run through the Layer 1–6 validation in order. E
240242
**Quick CORS verification from the browser console:**
241243

242244
```javascript
245+
// From Azure SWA
246+
fetch('https://app-talent-api-dev.azurewebsites.net/api/v1/health', {
247+
headers: { 'Origin': 'https://mango-flower-0ced4011e.4.azurestaticapps.net' }
248+
}).then(r => console.log('Status:', r.status, 'CORS:', r.headers.get('access-control-allow-origin')))
249+
250+
// From GitHub Pages
243251
fetch('https://app-talent-api-dev.azurewebsites.net/api/v1/health', {
244-
headers: { 'Origin': 'https://agreeable-desert-01234567.azurestaticapps.net' }
252+
headers: { 'Origin': 'https://workcontrolgit.github.io' }
245253
}).then(r => console.log('Status:', r.status, 'CORS:', r.headers.get('access-control-allow-origin')))
246254
```
247255

248-
Expected: `Status: 200 CORS: https://agreeable-desert-01234567.azurestaticapps.net`
256+
Expected for both: `Status: 200 CORS: <the origin you sent>`
249257

250258
---
251259

0 commit comments

Comments
 (0)