File tree Expand file tree Collapse file tree
1-Authentication/7-sign-in-express-mfa Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -74,15 +74,6 @@ class AuthProvider {
7474 ) ;
7575 }
7676
77- doesRequireMFA ( token ) {
78- // Decode the access token payload
79- const tokenPayload = JSON . parse ( atob ( token . split ( '.' ) [ 1 ] ) ) ;
80- console . log ( tokenPayload ) ;
81- // More infromation about the "mfa" can be found here.
82- // https://learn.microsoft.com/en-us/entra/identity-platform/access-token-claims-reference
83- return ! tokenPayload . amr . includes ( "mfa" ) ;
84- }
85-
8677 async handleRedirect ( req , res , next ) {
8778 const authCodeRequest = {
8879 ...req . session . authCodeRequest ,
Original file line number Diff line number Diff line change @@ -29,35 +29,32 @@ router.get('/id',
2929) ;
3030
3131router . get (
32- '/updateProfile ' ,
32+ '/gatedUpdateProfile ' ,
3333 isAuthenticated , // check if user is authenticated
3434 authProvider . getToken ( [ "User.ReadWrite" ] ) ,
3535 async function ( req , res , next ) {
36- let doesRequiredMFA = authProvider . doesRequireMFA ( req . session . accessToken ) ;
3736 const graphResponse = await fetch (
3837 GRAPH_ME_ENDPOINT ,
3938 req . session . accessToken
4039 ) ;
41- res . render ( "updateProfile " , {
40+ res . render ( "gatedUpdateProfile " , {
4241 profile : graphResponse ,
43- doesRequiredMFA : doesRequiredMFA
4442 } ) ;
4543 }
4644) ;
4745
4846router . get (
49- '/gatedUpdateProfile ' ,
47+ '/updateProfile ' ,
5048 isAuthenticated , // check if user is authenticated
5149 authProvider . getToken ( [ "User.ReadWrite" , mfaProtectedResourceScope ] ,
52- "http://localhost:3000/users/gatedUpdateProfile " ) , // check for mfa
50+ "http://localhost:3000/users/updateProfile " ) ,
5351 async function ( req , res , next ) {
5452 const graphResponse = await fetch (
5553 GRAPH_ME_ENDPOINT ,
5654 req . session . accessToken
5755 ) ;
5856 res . render ( "updateProfile" , {
5957 profile : graphResponse ,
60- doesRequiredMFA : false
6158 } ) ;
6259 }
6360) ;
Original file line number Diff line number Diff line change 1+ <h1 >Microsoft Graph API</h1 >
2+ <h3 >/me endpoint response</h3 >
3+ <div style =" display: flex; justify-content: left;" >
4+ <div style =" size: 400px;" >
5+ <form id =" userInfoForm" action =' /users/update' method =' POST' >
6+ <label >Id :</label >
7+ <label > {{ profile.id }} </label >
8+ <br />
9+ <label >Email :</label >
10+ <label > {{ profile.mail }} </label >
11+ <br />
12+ <label for =" userName" >Display Name :</label >
13+ <input type =" text" id =" displayName" name =" displayName" disabled value =" {{ profile.displayName }} " />
14+ <br />
15+ <label for =" userName" >Given Name :</label >
16+ <input type =" text" id =" givenName" name =" givenName" value =" {{ profile.givenName }} " />
17+ <br />
18+
19+ <label for =" userSurname" >Surname :</label >
20+ <input type =" text" id =" surname" name =" surname" value =" {{ profile.surname }} " />
21+ <br />
22+
23+ <button type =" submit" id =" button" >Save</button >
24+ </form >
25+ </div >
26+ <div >
27+ <br >
28+ <br >
29+ <a href =" /users/updateProfile" >
30+ <button >Edit</button >
31+ </a >
32+ </div >
33+ </div >
34+ <a href =" /" >Go back</a >
Original file line number Diff line number Diff line change 1- <h1 >Azure AD </h1 >
1+ <h1 >Entra ID </h1 >
22<h3 >ID Token</h3 >
33<table >
44 <tbody >
Original file line number Diff line number Diff line change 33<p >Hi {{ username }} !</p >
44<a href =" /users/id" >View ID token claims</a >
55<br >
6- <a href =" /users/updateProfile " >Profile editing</a >
6+ <a href =" /users/gatedUpdateProfile " >Profile editing</a >
77<br >
88<a href =" /auth/signout" >Sign out</a >
99{{ else }}
Original file line number Diff line number Diff line change 11<h1 >Microsoft Graph API</h1 >
22<h3 >/me endpoint response</h3 >
3- <div style =" display: flex; justify-content: left;" >
3+ <div style =" display: flex; justify-content: left;" >
44<div style =" size: 400px;" >
55 <form id =" userInfoForm" action =' /users/update' method =' POST' >
66 <label >Id :</label >
1010 <label > {{ profile.mail }} </label >
1111 <br />
1212 <label for =" userName" >Display Name :</label >
13- <input type =" text" id =" displayName" name =" displayName" {{ #if doesRequiredMFA }} disabled {{ else }} {{ /if }} value =" {{ profile.displayName }} " />
13+ <input type =" text" id =" displayName" name =" displayName" value =" {{ profile.displayName }} " />
1414 <br />
1515 <label for =" userName" >Given Name :</label >
1616 <input type =" text" id =" givenName" name =" givenName" value =" {{ profile.givenName }} " />
2323 <button type =" submit" id =" button" >Save</button >
2424 </form >
2525</div >
26- <div >
27- <br >
28- <br >
29- {{ #if doesRequiredMFA }}
30- <a href =" /users/gatedUpdateProfile" >
31- <button >Edit</button >
32- </a >
33- {{ else }}
34- <br />
35- {{ /if }}
36- </div >
26+ <br >
3727</div >
3828<a href =" /" >Go back</a >
Original file line number Diff line number Diff line change 11{
22 "Sample" : {
3- "Title" : " A Node.js & Express web app authenticating users against Azure AD for Customers with MSAL Node" ,
3+ "Title" : " A Node.js & Express web app authenticating users against Entra ID for Customers with MSAL Node" ,
44 "Level" : 100 ,
55 "Client" : " Node.js & Express web app" ,
66 "Languages" : [
1414 "Endpoint" : " AAD v2.0" ,
1515 "Provider" : " CIAM" ,
1616 "Platform" : " JavaScript" ,
17- "description" : " This sample demonstrates a Node.js & Express web app authenticating users against Azure Active Directory Customer Identity Access Management (Azure AD for Customers) with Microsoft Authentication Library for Node (MSAL Node)"
17+ "description" : " This sample demonstrates a Node.js & Express web app authenticating users with Microsoft Entra External ID using the Microsoft Authentication Library for Node (MSAL Node)"
1818 },
1919 "AADApps" : [
2020 {
You can’t perform that action at this time.
0 commit comments