Skip to content
This repository has been archived by the owner. It is now read-only.

Commit c933c29

Browse files
committed
update lib + code changes
1 parent 749a067 commit c933c29

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

JavaScriptSPA/index.html

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
</div>
2020
<script>
2121
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"
2626
};
2727

2828
var config = {
@@ -68,7 +68,7 @@
6868
}).catch(function (error) {
6969
console.log(error);
7070
// 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)) {
7272
myMSALObj.acquireTokenPopup(tokenRequest).then(function (tokenResponse) {
7373
callMSGraph(applicationConfig.graphEndpoint, tokenResponse.accessToken, graphAPICallback);
7474
}).catch(function (error) {
@@ -97,7 +97,6 @@
9797
function showWelcomeMessage() {
9898
var divWelcome = document.getElementById('WelcomeMessage');
9999
divWelcome.innerHTML = 'Welcome ' + myMSALObj.getAccount().userName + "to Microsoft Graph API";
100-
console.log(myMSALObj.getAccount());
101100
var loginbutton = document.getElementById('SignIn');
102101
loginbutton.innerHTML = 'Sign Out';
103102
loginbutton.setAttribute('onclick', 'signOut();');
@@ -111,12 +110,11 @@
111110
scopes: applicationConfig.graphScopes
112111
};
113112
myMSALObj.acquireTokenSilent(tokenRequest).then(function (tokenResponse) {
114-
console.log(tokenResponse.scopes);
115113
callMSGraph(applicationConfig.graphEndpoint, tokenResponse.accessToken, graphAPICallback);
116114
}).catch(function (error) {
117115
console.log(error);
118116
//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)) {
120118
myMSALObj.acquireTokenRedirect(tokenRequest);
121119
}
122120
});
@@ -134,7 +132,14 @@
134132
console.log(error);
135133
}
136134

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+
}
138143
// Browser check variables
139144
var ua = window.navigator.userAgent;
140145
var msie = ua.indexOf('MSIE ');
@@ -153,10 +158,10 @@
153158
}
154159
else {
155160
document.getElementById("SignIn").onclick = function () {
156-
let tokenRequest = {
161+
let redirectTokenRequest = {
157162
scopes: applicationConfig.graphScopes
158163
};
159-
myMSALObj.loginRedirect(tokenRequest);
164+
myMSALObj.loginRedirect(redirectTokenRequest);
160165
};
161166

162167
if (myMSALObj.getAccount() && !myMSALObj.isCallback(window.location.hash)) {// avoid duplicate code execution on page load in case of iframe and popup window.

JavaScriptSPA/msal-0.9.0.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)