Skip to content

Commit 1a96ef7

Browse files
committed
review changes
1 parent 31a6fc2 commit 1a96ef7

6 files changed

Lines changed: 27 additions & 28 deletions

File tree

2-Authorization-I/1-call-graph/App/public/401.html

Lines changed: 0 additions & 1 deletion
This file was deleted.

2-Authorization-I/1-call-graph/App/utils/msalExpressMiddleware.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ class MsalExpressMiddleware extends msal.ConfidentialClientApplication {
167167
// edit here if you would like to change redirect after successful login
168168
return res.status(200).redirect(this.rawConfig.configuration.homePageRoute);
169169
} else {
170-
return res.status(401).redirect('/401.html');
170+
return res.status(401).send("Not Permitted");
171171
}
172172
}).catch((error) => {
173173
console.log(error);
@@ -202,10 +202,10 @@ class MsalExpressMiddleware extends msal.ConfidentialClientApplication {
202202
res.status(500).send(error);
203203
});
204204
} else {
205-
res.status(500).send("unknown");
205+
res.status(500).send("Unknown app stage");
206206
}
207207
} else {
208-
res.status(401).redirect('/401.html');
208+
res.status(401).send("Not Permitted");
209209
}
210210
};
211211

@@ -241,23 +241,23 @@ class MsalExpressMiddleware extends msal.ConfidentialClientApplication {
241241
// initiate the first leg of auth code grant to get token
242242
this.getAuthCode(
243243
this.msalConfig.auth.authority,
244-
scopes, state, this.msalConfig.auth.redirectUri, res
245-
);
246-
244+
scopes, state,
245+
this.msalConfig.auth.redirectUri,
246+
res);
247247
} else {
248248
next();
249249
}
250250
};
251251

252252
/**
253-
* Middleware checks for id token (and redirects to get sign-in?)
253+
* Middleware checks for id token (and redirects to sign-in?)
254254
* @param {Object} req: express request object
255255
* @param {Object} res: express response object
256256
* @param {Function} next: express next
257257
*/
258258
isAuthenticated = (req, res, next) => {
259259
if (!req.session.isAuthenticated) {
260-
return res.redirect('/401.html');
260+
return res.send("Not Permitted");
261261
}
262262
next();
263263
};
@@ -279,7 +279,7 @@ class MsalExpressMiddleware extends msal.ConfidentialClientApplication {
279279
}
280280

281281
if (!this.hasTokenForProtectedRoute(req.session, resourceName)) {
282-
return res.redirect('/401.html');
282+
return res.send("Not Permitted");
283283
}
284284
next();
285285
};
@@ -306,7 +306,7 @@ class MsalExpressMiddleware extends msal.ConfidentialClientApplication {
306306

307307
/**
308308
* Validates the access token for signature
309-
* and a given set of claims
309+
* and against a predefined set of claims
310310
* @param {Object} token: raw access token
311311
*/
312312
validateAccessToken = (accessToken) => {
@@ -341,7 +341,7 @@ class MsalExpressMiddleware extends msal.ConfidentialClientApplication {
341341
*/
342342
getSigningKeys = (header, callback) => {
343343
const client = jwksClient({
344-
jwksUri: 'https://login.microsoftonline.com/' + this.rawConfig.credentials.tenantId + '/discovery/v2.0/keys'
344+
jwksUri: `${constants.AuthorityStrings.AAD}${this.rawConfig.credentials.tenantId}/discovery/v2.0/keys`
345345
});
346346

347347
client.getSigningKey(header.kid, function (err, key) {
@@ -413,7 +413,7 @@ class MsalExpressMiddleware extends msal.ConfidentialClientApplication {
413413

414414
/**
415415
* Util method to get the resource name for a given callingPageRoute (auth.json)
416-
* @param {String} path
416+
* @param {String} path: /path string that the resource is associated with
417417
*/
418418
getResourceName = (path) => {
419419
let index = Object.values(this.rawConfig.resources).findIndex(resource => resource.callingPageRoute === path);

2-Authorization-I/1-call-graph/AppCreationScripts/Cleanup.ps1

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ Function Cleanup
5959
# Removes the applications
6060
Write-Host "Cleaning-up applications from tenant '$tenantName'"
6161

62-
Write-Host "Removing 'webApp' (ExpressWebApp-3) if needed"
63-
Get-AzureADApplication -Filter "DisplayName eq 'ExpressWebApp-3'" | ForEach-Object {Remove-AzureADApplication -ObjectId $_.ObjectId }
64-
$apps = Get-AzureADApplication -Filter "DisplayName eq 'ExpressWebApp-3'"
62+
Write-Host "Removing 'webApp' (ExpressWebApp-2) if needed"
63+
Get-AzureADApplication -Filter "DisplayName eq 'ExpressWebApp-2'" | ForEach-Object {Remove-AzureADApplication -ObjectId $_.ObjectId }
64+
$apps = Get-AzureADApplication -Filter "DisplayName eq 'ExpressWebApp-2'"
6565
if ($apps)
6666
{
6767
Remove-AzureADApplication -ObjectId $apps.ObjectId
@@ -70,10 +70,10 @@ Function Cleanup
7070
foreach ($app in $apps)
7171
{
7272
Remove-AzureADApplication -ObjectId $app.ObjectId
73-
Write-Host "Removed ExpressWebApp-3.."
73+
Write-Host "Removed ExpressWebApp-2.."
7474
}
7575
# also remove service principals of this app
76-
Get-AzureADServicePrincipal -filter "DisplayName eq 'ExpressWebApp-3'" | ForEach-Object {Remove-AzureADServicePrincipal -ObjectId $_.Id -Confirm:$false}
76+
Get-AzureADServicePrincipal -filter "DisplayName eq 'ExpressWebApp-2'" | ForEach-Object {Remove-AzureADServicePrincipal -ObjectId $_.Id -Confirm:$false}
7777

7878
}
7979

2-Authorization-I/1-call-graph/AppCreationScripts/Configure.ps1

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -192,17 +192,17 @@ Function ConfigureApplications
192192
$user = Get-AzureADUser -ObjectId $creds.Account.Id
193193

194194
# Create the webApp AAD application
195-
Write-Host "Creating the AAD application (ExpressWebApp-3)"
195+
Write-Host "Creating the AAD application (ExpressWebApp-2)"
196196
# Get a 2 years application key for the webApp Application
197197
$pw = ComputePassword
198198
$fromDate = [DateTime]::Now;
199199
$key = CreateAppKey -fromDate $fromDate -durationInYears 2 -pw $pw
200200
$webAppAppKey = $pw
201201
# create the application
202-
$webAppAadApplication = New-AzureADApplication -DisplayName "ExpressWebApp-3" `
203-
-HomePage "https://localhost:4000/" `
202+
$webAppAadApplication = New-AzureADApplication -DisplayName "ExpressWebApp-2" `
203+
-HomePage "http://localhost:4000/" `
204204
-ReplyUrls "http://localhost:4000/redirect" `
205-
-IdentifierUris "https://$tenantName/ExpressWebApp-3" `
205+
-IdentifierUris "https://$tenantName/ExpressWebApp-2" `
206206
-PasswordCredentials $key `
207207
-PublicClient $False
208208

@@ -219,12 +219,12 @@ Function ConfigureApplications
219219
}
220220

221221

222-
Write-Host "Done creating the webApp application (ExpressWebApp-3)"
222+
Write-Host "Done creating the webApp application (ExpressWebApp-2)"
223223

224224
# URL of the AAD application in the Azure portal
225225
# Future? $webAppPortalUrl = "https://portal.azure.com/#@"+$tenantName+"/blade/Microsoft_AAD_RegisteredApps/ApplicationMenuBlade/Overview/appId/"+$webAppAadApplication.AppId+"/objectId/"+$webAppAadApplication.ObjectId+"/isMSAApp/"
226226
$webAppPortalUrl = "https://portal.azure.com/#blade/Microsoft_AAD_RegisteredApps/ApplicationMenuBlade/CallAnAPI/appId/"+$webAppAadApplication.AppId+"/objectId/"+$webAppAadApplication.ObjectId+"/isMSAApp/"
227-
Add-Content -Value "<tr><td>webApp</td><td>$currentAppId</td><td><a href='$webAppPortalUrl'>ExpressWebApp-3</a></td></tr>" -Path createdApps.html
227+
Add-Content -Value "<tr><td>webApp</td><td>$currentAppId</td><td><a href='$webAppPortalUrl'>ExpressWebApp-2</a></td></tr>" -Path createdApps.html
228228

229229
$requiredResourcesAccess = New-Object System.Collections.Generic.List[Microsoft.Open.AzureAD.Model.RequiredResourceAccess]
230230

2-Authorization-I/1-call-graph/AppCreationScripts/sample.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
"AADApps": [
1111
{
1212
"Id": "webApp",
13-
"Name": "ExpressWebApp-3",
13+
"Name": "ExpressWebApp-2",
1414
"Kind": "WebApp",
1515
"Audience": "AzureADMyOrg",
16-
"HomePage": "https://localhost:4000/",
16+
"HomePage": "http://localhost:4000/",
1717
"ReplyUrls": "http://localhost:4000/redirect",
1818
"PasswordCredentials": "Auto",
1919
"RequiredResourcesAccess": [

2-Authorization-I/1-call-graph/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ Open the project in your IDE (like Visual Studio or Visual Studio Code) to confi
162162
1. Find the key `tenantId` and replace the existing value with your Azure AD **tenant ID**.
163163
1. Find the key `clientSecret` and replace the existing value with the key you saved during the creation of the `ExpressWebApp` app, in the Azure Portal.
164164
1. Find the key `homePageRoute` and replace the existing value with the route that you wish to be redirected after sign-in, e.g. `/home`.
165-
1. Find the key `redirectUri` and replace the existing value with the **Redirect URI** for `ExpressWebApp` app. For example, `https://localhost:4000/redirect`.
166-
1. Find the `postLogoutRedirectUri` and replace the existing value with the URI that you wish to be redirected after sign-out, e.g. `https://localhost:4000/`
165+
1. Find the key `redirectUri` and replace the existing value with the **Redirect URI** for `ExpressWebApp` app. For example, `http://localhost:4000/redirect`.
166+
1. Find the `postLogoutRedirectUri` and replace the existing value with the URI that you wish to be redirected after sign-out, e.g. `http://localhost:4000/`
167167

168168
The rest of the **key-value** pairs are for resources/APIs that you would like to call. They are set as **default**, but you can modify them as you wish:
169169

0 commit comments

Comments
 (0)