Replies: 7 comments 1 reply
-
|
Nevermind, the popup approach doesn't actually work here at all because auth0 tries to use a webmessage response, and Office doesn't allow cross-origin messages from dialogs without its special API too. But I realized that if (!isAuthenticated) {
let dialog: Office.Dialog;
// Strategy: the popup will pass its redirect-callback data here, so we can pass it on to handleRedirectCallback
const processMessage = async (
args:
| { message: string; origin: string | undefined }
| { error: number }
) => {
if ('error' in args) {
console.error('Error:', args.error);
return;
}
let messageFromDialog = JSON.parse(args.message);
dialog.close();
if (messageFromDialog.status === 'success') {
// The dialog reported a successful login.
handleRedirectCallback(messageFromDialog.urlWithAuthInfo);
}
else {
console.error('Login failed.', messageFromDialog);
}
};
// Actually make a popup using MS dialog API
// hook the message event from the popup to set close false and get the token
return (
<div>
Login here:
<button onClick= { async () => {
// Use this dialog for the Auth0 client library.
await loginWithRedirect({
openUrl: async (url: string) => {
const redirect = encodeURIComponent(url);
const bounceURL = location.protocol + '//' + location.hostname + (location.port ? ':' + location.port : '') + '/popup.html?redirect=' + redirect;
// height and width are percentages of the size of the screen.
// How MS use it: https://github.com/OfficeDev/Office-Add-in-samples/blob/main/Samples/auth/Office-Add-in-Microsoft-Graph-React/utilities/office-apis-helpers.ts#L38
Office.context.ui.displayDialogAsync(
bounceURL,
{ height: 45, width: 55 },
function (result) {
dialog = result.value;
dialog.addEventHandler(
Office.EventType.DialogMessageReceived,
processMessage
);
}
);
}
});
}}
>Log in
</button>
</div>
);
}Handling log-out is a different story... we haven't figured that out yet! |
Beta Was this translation helpful? Give feedback.
-
|
We've realized that we sometimes want to call |
Beta Was this translation helpful? Give feedback.
-
|
Trying to understand the specific ask here a bit better. Avoiding using the browser's API's to open the URL to Auth0 can be achieved using I do not think there is much of a change we can implement if you know that:
|
Beta Was this translation helpful? Give feedback.
-
|
I think the We're thinking about simply dropping auth0 and rolling our own oauth2; we've spent too much effort on all the papercuts here. (Maybe a custom domain could fix it, but I'm not sure how because it would still technically be cross-origin: I'm not going to submit a PR myself here, but I got a reasonable response when I messaged GitHub Copilot with this request in Auth0Client.ts:
But note that this still doesn't address the problem of using the wrong API to message parent; at least the response_type parameter would need to be customizable I guess. |
Beta Was this translation helpful? Give feedback.
-
There is no such thing to just retrieve a token using a redirect when relying on the Authorization Code Flow. If you want to redirect, you can use
Not sure what you want to solve with custom domains, but custom domains does help solve 3rd party cookie issues as it only accounts for the top level domain. That said, this SDK is built for SPA applications, not Office Addins. Happy to see how we can help you integrate it, but it's expected not to be just plug and play. |
Beta Was this translation helpful? Give feedback.
-
|
To be clear: we're using I'm not asking for this to be plug-and-play, but if the code were more modular we could build our solution using its pieces. |
Beta Was this translation helpful? Give feedback.
-
|
Hi @kcarnold, Thanks for the detailed exploration of this use case. I will be converting this to a GitHub Discussion.
Thanks again for your contributions! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Checklist
Describe the problem you'd like to have solved
Microsoft Office add-ins require that any popups be opened using a special API instead of
window.open. A few unusual constraints of that API are:Describe the ideal solution
I've done some gymnastics (see below) to make this API work with
loginWithPopup, but it would be much easier if the user of the library could provide a custom dialog API. For example, something like:where I've imagined asyncified versions of the Office dialog code.
Alternatives and current workarounds
My workaround code currently looks like:
Additional context
No response
Beta Was this translation helpful? Give feedback.
All reactions