|
19 | 19 | </div> |
20 | 20 | <script> |
21 | 21 | var applicationConfig = { |
22 | | - clientID: 'Enter_the_Application_Id_here', //This is your client ID |
23 | | - authority: "https://login.microsoftonline.com/Enter_the_Tenant_Info_Here", //Default authority value is https://login.microsoftonline.com/common |
24 | | - graphScopes: ["user.read"], |
25 | | - graphEndpoint: "https://graph.microsoft.com/v1.0/me" |
| 22 | + clientID: "245e9392-c666-4d51-8f8a-bfd9e55b2456", |
| 23 | + authority: "https://login.microsoftonline.com/common", |
| 24 | + graphScopes: ["user.read", "Mail.Send"], |
| 25 | + graphEndpoint: "https://graph.microsoft.com/v1.0/me" |
26 | 26 | }; |
27 | 27 |
|
28 | 28 | var config = { |
|
68 | 68 | }).catch(function (error) { |
69 | 69 | console.log(error); |
70 | 70 | // Call acquireTokenPopup (popup window) in case of acquireTokenSilent failure due to consent or interaction required ONLY |
71 | | - if (error.errorMessage.indexOf("consent_required") !== -1 || error.errorMessage.indexOf("interaction_required") !== -1 || error.errorMessage.indexOf("login_required") !== -1) { |
| 71 | + if (requiresInteraction(error.errorMessage)) { |
72 | 72 | myMSALObj.acquireTokenPopup(tokenRequest).then(function (tokenResponse) { |
73 | 73 | callMSGraph(applicationConfig.graphEndpoint, tokenResponse.accessToken, graphAPICallback); |
74 | 74 | }).catch(function (error) { |
|
97 | 97 | function showWelcomeMessage() { |
98 | 98 | var divWelcome = document.getElementById('WelcomeMessage'); |
99 | 99 | divWelcome.innerHTML = 'Welcome ' + myMSALObj.getAccount().userName + "to Microsoft Graph API"; |
100 | | - console.log(myMSALObj.getAccount()); |
101 | 100 | var loginbutton = document.getElementById('SignIn'); |
102 | 101 | loginbutton.innerHTML = 'Sign Out'; |
103 | 102 | loginbutton.setAttribute('onclick', 'signOut();'); |
|
111 | 110 | scopes: applicationConfig.graphScopes |
112 | 111 | }; |
113 | 112 | myMSALObj.acquireTokenSilent(tokenRequest).then(function (tokenResponse) { |
114 | | - console.log(tokenResponse.scopes); |
115 | 113 | callMSGraph(applicationConfig.graphEndpoint, tokenResponse.accessToken, graphAPICallback); |
116 | 114 | }).catch(function (error) { |
117 | 115 | console.log(error); |
118 | 116 | //Call acquireTokenRedirect in case of acquireToken Failure |
119 | | - if (error.errorMessage.indexOf("consent_required") !== -1 || error.errorMessage.indexOf("interaction_required") !== -1 || error.errorMessage.indexOf("login_required") !== -1) { |
| 117 | + if (requiresInteraction(error.errorMessage)) { |
120 | 118 | myMSALObj.acquireTokenRedirect(tokenRequest); |
121 | 119 | } |
122 | 120 | }); |
|
134 | 132 | console.log(error); |
135 | 133 | } |
136 | 134 |
|
137 | | - |
| 135 | + function requiresInteraction(errorMessage) { |
| 136 | + if (!errorMessage || !errorMessage.length) { |
| 137 | + return false; |
| 138 | + } |
| 139 | + return errorMessage.indexOf("consent_required") !== -1 || |
| 140 | + errorMessage.indexOf("interaction_required") !== -1 || |
| 141 | + errorMessage.indexOf("login_required") !== -1; |
| 142 | + } |
138 | 143 | // Browser check variables |
139 | 144 | var ua = window.navigator.userAgent; |
140 | 145 | var msie = ua.indexOf('MSIE '); |
|
153 | 158 | } |
154 | 159 | else { |
155 | 160 | document.getElementById("SignIn").onclick = function () { |
156 | | - let tokenRequest = { |
| 161 | + let redirectTokenRequest = { |
157 | 162 | scopes: applicationConfig.graphScopes |
158 | 163 | }; |
159 | | - myMSALObj.loginRedirect(tokenRequest); |
| 164 | + myMSALObj.loginRedirect(redirectTokenRequest); |
160 | 165 | }; |
161 | 166 |
|
162 | 167 | if (myMSALObj.getAccount() && !myMSALObj.isCallback(window.location.hash)) {// avoid duplicate code execution on page load in case of iframe and popup window. |
|
0 commit comments