Skip to content

Commit 0faecf1

Browse files
committed
ch2 review
1 parent 2e9c7e6 commit 0faecf1

32 files changed

Lines changed: 460 additions & 3297 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,6 @@ dist
102102

103103
# TernJS port file
104104
.tern-port
105+
106+
# NPM lock file
107+
package-lock.json

1-Authentication/1-sign-in/App/routes/router.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ router.get('/signout', identity.signOut);
1616
router.get('/redirect', identity.handleRedirect);
1717

1818
// protected routes
19-
router.get('/profile', identity.isAuthenticated, identity.getToken, mainController.getProfile); // get token for this route to call web API
19+
router.get('/profile', identity.isAuthenticated, mainController.getProfile);
2020

2121
// 404
2222
router.get('*', (req, res) => res.status(404).redirect('/404.html'));

1-Authentication/1-sign-in/App/utils/identity.js

Lines changed: 0 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -154,48 +154,13 @@ exports.signOut = (req, res) => {
154154
});
155155
};
156156

157-
exports.getToken = (req, res, next) => {
158-
if (!req.session.graphToken) {
159-
160-
nonce = generateGuid();
161-
162-
const authCodeUrlParameters = {
163-
redirectUri: auth.configuration.redirectUri,
164-
scopes: auth.resources.graphAPI.scopes,
165-
state: base64EncodeUrl(JSON.stringify({
166-
stage: APP_STATES.acquireToken,
167-
path: req.route.path,
168-
nonce: nonce
169-
}))
170-
};
171-
172-
// get url to sign user in and consent to scopes needed for application
173-
msalClient.getAuthCodeUrl(authCodeUrlParameters)
174-
.then((response) => {
175-
return res.redirect(response);
176-
}).catch((error) => {
177-
console.log(JSON.stringify(error));
178-
return res.status(500).send(JSON.stringify(error));
179-
});
180-
} else {
181-
next();
182-
}
183-
};
184-
185157
exports.isAuthenticated = (req, res, next) => {
186158
if (!req.session.isAuthenticated) {
187159
return res.redirect('/401.html');
188160
}
189161
next();
190162
};
191163

192-
exports.isAuthorized = (req, res, next) => {
193-
if (!req.session.graphToken) {
194-
return res.redirect('/401.html');
195-
}
196-
next();
197-
}
198-
199164
// ========= UTILITIES ============
200165

201166
const validateIdToken = (idTokenClaims) => {
@@ -212,56 +177,6 @@ const validateIdToken = (idTokenClaims) => {
212177
}
213178
};
214179

215-
const validateAccessToken = (token) => {
216-
console.log(token);
217-
218-
// TODO: claims validation logic
219-
// check scp
220-
// check audience
221-
// check issuer
222-
// check tid if allowed
223-
// check nonce replay
224-
225-
const validationOptions = {
226-
audience: auth.credentials.clientId,
227-
}
228-
229-
// without verifying signature
230-
// var decoded = jwt.decode(token, {complete: true});
231-
232-
jwt.verify(token, getSigningKeys, validationOptions, (err, payload) => {
233-
if (err) {
234-
console.log(err);
235-
}
236-
console.log(payload);
237-
});
238-
};
239-
240-
const getSigningKeys = (header, callback) => {
241-
const client = jwksClient({
242-
jwksUri: 'https://login.microsoftonline.com/' + auth.credentials.tenantId + '/discovery/v2.0/keys'
243-
});
244-
245-
client.getSigningKey(header.kid, function (err, key) {
246-
const signingKey = key.publicKey || key.rsaPublicKey;
247-
callback(null, signingKey);
248-
});
249-
};
250-
251-
const callAPI = (endpoint, accessToken, callback) => {
252-
const options = {
253-
headers: {
254-
Authorization: `Bearer ${accessToken}`
255-
}
256-
};
257-
258-
console.log('request made to web API at: ' + new Date().toString());
259-
260-
axios.default.get(endpoint, options)
261-
.then(response => callback(response.data))
262-
.catch(error => console.log(error));
263-
}
264-
265180
// ======== CRYPTO UTILS ==========
266181

267182
const base64Encode = (str, encoding) => {

1-Authentication/1-sign-in/App/views/home.ejs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
<div id="card-div" class="col-md-3">
1717
<div class="card text-center">
1818
<div class="card-body">
19-
<h5 class="card-description">Sign-in to access your tasks</h5>
2019
<% if (isAuthenticated) { %>
21-
<a class="btn btn-primary" href="/read" "role="button">Get my tasks</a>
22-
<a class="btn btn-primary" href="/write" "role="button">Add a task</a>
23-
<% } %>
20+
<h5 class="card-description">Welcome!</h5>
21+
<% } else { %>
22+
<h5 class="card-description">Sign-in to get an ID Token</h5>
23+
<% } %>
2424
</div>
2525
</div>
2626
</div>
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<footer class="footer font-small blue">
2-
<div class="footer text-center py-3">© 2020 Microsoft identity platform
3-
<a href="https://aka.ms/aadv2"> aka.ms/aadv2</a>
2+
<div class="footer text-center py-3">How did we do?
3+
<a href="https://forms.office.com/Pages/ResponsePage.aspx?id=v4j5cvGGr0GRqy180BHbR73pcsbpbxNJuZCMKN0lURpUQkRCSVdRSk8wUjdZSkg2NEZGOFFaTkxQVyQlQCN0PWcu" target="_blank">Share your experience with us!</a>
44
</div>
55
</footer>

1-Authentication/1-sign-in/AppCreationScripts/AppCreationScripts.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ The `Configure.ps1` will stop if it tries to create an Azure AD application whic
7575
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process
7676
```
7777
78-
1. ### (Optionally) install AzureAD PowerShell modules
79-
2.
78+
### (Optionally) install AzureAD PowerShell modules
79+
8080
The scripts install the required PowerShell module (AzureAD) for the current user if needed. However, if you want to install if for all users on the machine, you can follow the following steps:
8181
8282
1. If you have never done it already, in the PowerShell window, install the AzureAD PowerShell modules. For this:

0 commit comments

Comments
 (0)