Skip to content
This repository has been archived by the owner on Jun 9, 2021. It is now read-only.

Commit

Permalink
Updated SSO flow to prompt
Browse files Browse the repository at this point in the history
When SSO returns a 13007 or 13005 from a non-prompting call to `getAccessTokenAsync`, repeat the call with `forceConsent=true`.
  • Loading branch information
jasonjoh committed Apr 5, 2018
1 parent e2eadd3 commit a89becb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
15 changes: 14 additions & 1 deletion AttachmentDemoWeb/Functions/FunctionFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,24 @@ function saveAllAttachments(event) {
if (result.status === "succeeded") {
// No need to prompt user, use this token to call Web API
saveAllAttachmentsWithSSO(result.value, event);
} else if (result.error.code == 13007 || result.error.code == 13005) {
// These error codes indicate that we need to prompt for consent
Office.context.auth.getAccessTokenAsync({ forceConsent: true }, function (result) {
if (result.status === "succeeded") {
saveAllAttachmentsWithSSO(result.value, event);
} else {
// Could not get SSO token, proceed with authentication prompt
saveAllAttachmentsWithPrompt(event);
}
});
} else {
// Could not get SSO token, proceed with authentication prompt
saveAllAttachmentsWithPrompt(event);
}
});
} else {
// SSO not supported
saveAllAttachmentsWithPrompt(event);
}
}

Expand Down Expand Up @@ -81,7 +94,7 @@ function saveAllAttachmentsWithPrompt(event) {
});

authenticator
.authenticate("Microsoft")
.authenticate(OfficeHelpers.DefaultEndpoints.Microsoft, true)
.then(function (token) {
showProgress("Retrieving Outlook callback token");

Expand Down
15 changes: 14 additions & 1 deletion AttachmentDemoWeb/MessageRead.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,24 @@
if (result.status === "succeeded") {
// No need to prompt user, use this token to call Web API
saveAttachmentsWithSSO(result.value, attachmentIds);
} else if (result.error.code == 13007 || result.error.code == 13005) {
// These error codes indicate that we need to prompt for consent
Office.context.auth.getAccessTokenAsync({ forceConsent: true }, function (result) {
if (result.status === "succeeded") {
saveAttachmentsWithSSO(result.value, attachmentIds);
} else {
// Could not get SSO token, proceed with authentication prompt
saveAttachmentsWithPrompt(attachmentIds);
}
});
} else {
// Could not get SSO token, proceed with authentication prompt
saveAttachmentsWithPrompt(attachmentIds);
}
});
} else {
// SSO not supported
saveAttachmentsWithPrompt(attachmentIds);
}
}

Expand Down Expand Up @@ -198,7 +211,7 @@

function saveAttachmentsWithPrompt(attachmentIds) {
authenticator
.authenticate(OfficeHelpers.DefaultEndpoints.Microsoft)
.authenticate(OfficeHelpers.DefaultEndpoints.Microsoft, true)
.then(function (token) {
// Get callback token, which grants read access to the current message
// via the Outlook API
Expand Down

0 comments on commit a89becb

Please sign in to comment.