Skip to content

Commit 2b760e7

Browse files
author
derisen
committed
sync
1 parent 9423bb6 commit 2b760e7

6 files changed

Lines changed: 103 additions & 4 deletions

File tree

2-Authorization/1-call-graph/App/controllers/mainController.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@ exports.getHomePage = (req, res, next) => {
33
res.render('home', { isAuthenticated: isAuthenticated });
44
}
55

6-
exports.getProfile = (req, res, next) => {
6+
exports.getProfilePage = (req, res, next) => {
7+
const isAuthenticated = req.session.isAuthenticated;
8+
const profile = req.session.graphAPI["resourceResponse"]; // the name of your api in auth.json
9+
res.render('profile', {isAuthenticated: isAuthenticated, profile: profile});
10+
}
11+
12+
exports.getIdPage = (req, res, next) => {
713
const isAuthenticated = req.session.isAuthenticated;
814
const claims = req.session.idTokenClaims;
9-
res.render('profile', {isAuthenticated: isAuthenticated, claims: claims});
15+
res.render('id', {isAuthenticated: isAuthenticated, claims: claims});
1016
}

2-Authorization/1-call-graph/App/routes/router.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ router.get('/signout', msal.signOut);
2121
router.get('/redirect', msal.handleRedirect);
2222

2323
// protected routes
24-
router.get('/profile', msal.isAuthenticated, msal.getToken, mainController.getProfile); // get token for this route to call web API
24+
router.get('/profile', msal.isAuthenticated, msal.getToken, mainController.getProfilePage); // get token for this route to call web API
25+
router.get('/id', msal.isAuthenticated, mainController.getIdPage);
2526
router.get('/write', msal.isAuthenticated, todoController.writeNote);
2627
router.post('/write', msal.isAuthenticated, todoController.postNote);
2728
router.get('/notes/:noteId', msal.isAuthenticated, todoController.seeNote);
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" status="width=device-width, initial-scale=1.0">
6+
7+
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
8+
<link rel="stylesheet" href="/style.css">
9+
<title>ID</title>
10+
</head>
11+
<body>
12+
13+
<%- include('includes/navbar', {isAuthenticated: isAuthenticated}); %>
14+
15+
<div class="table-area-div">
16+
<table class="table">
17+
<thead class="thead-dark">
18+
<tr>
19+
<th scope="col">Claim</th>
20+
<th scope="col">Value</th>
21+
</tr>
22+
</thead>
23+
<tbody>
24+
<% for (const [key, value] of Object.entries(claims)) { %>
25+
<tr>
26+
<td><%= key %></td>
27+
<td><%= value %></td>
28+
</tr>
29+
<% } %>
30+
</tbody>
31+
</table>
32+
</div>
33+
34+
<%- include('includes/footer'); %>
35+
36+
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
37+
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
38+
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
39+
</body>
40+
</html>

2-Authorization/1-call-graph/App/views/includes/navbar.ejs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<div class="btn-group ml-auto dropleft">
44
<% if (isAuthenticated) { %>
55
<a class="btn btn-secondary" href="/profile" role="button">Profile</a>
6+
<a class="btn btn-secondary" href="/id" role="button">ID</a>
67
<a class="btn btn-success" href="/signout" role="button">Sign-out</a>
78
<% } else { %>
89
<a class="btn btn-secondary" href="/signin" role="button">Sign-in</a>

2-Authorization/1-call-graph/App/views/profile.ejs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
</tr>
2222
</thead>
2323
<tbody>
24-
<% for (const [key, value] of Object.entries(claims)) { %>
24+
<% for (const [key, value] of Object.entries(profile)) { %>
2525
<tr>
2626
<td><%= key %></td>
2727
<td><%= value %></td>
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"Sample": {
3+
"Title": "A Node.js & Express Web App calling Microsoft Graph API using MSAL Node",
4+
"Level": 100,
5+
"Client": "Node.js Express Web App",
6+
"RepositoryUrl": "ms-identity-javascript-nodejs-tutorial",
7+
"Endpoint": "AAD v2.0"
8+
},
9+
"AADApps": [
10+
{
11+
"Id": "webApp",
12+
"Name": "ExpressWebApp-3",
13+
"Kind": "WebApp",
14+
"Audience": "AzureADMyOrg",
15+
"HomePage": "https://localhost:4000/",
16+
"ReplyUrls": "http://localhost:4000/redirect",
17+
"PasswordCredentials": "Auto",
18+
"RequiredResourcesAccess": [
19+
{
20+
"Resource": "Microsoft Graph",
21+
"DelegatedPermissions": [ "User.Read" ]
22+
}
23+
]
24+
}
25+
],
26+
"CodeConfiguration": [
27+
{
28+
"App": "webApp",
29+
"SettingKind": "JSON",
30+
"SettingFile": "\\..\\auth.json",
31+
"Mappings": [
32+
{
33+
"key": "clientId",
34+
"value": ".AppId"
35+
},
36+
{
37+
"key": "tenantId",
38+
"value": "$tenantId"
39+
},
40+
{
41+
"key": "clientSecret",
42+
"value": ".AppKey"
43+
},
44+
{
45+
"key": "redirectUri",
46+
"value": ".ReplyUrls"
47+
}
48+
]
49+
}
50+
]
51+
}

0 commit comments

Comments
 (0)