Search code examples
single-page-applicationoffice-jsoffice-addinsoutlook-web-addinsoffice-dialog-api

How to read redirected url parameters from Office.context.ui.displayDialogAsync


I am stuck on how to read url parameters/token from redirected page url in Outlook web-addin. I am using DialogAPI to pop up my azure app sign-in/consent page and then trying to read tokens from redirected page.

I can see that token are passed but I couldn't figure out how to read token from url?

function GetToken(url)
{
_dlg = Office.context.ui.displayDialogAsync(url, { height: 40, width: 40 }, function (result) {
                _dlg = result.value;
                _dlg.addEventHandler(Office.EventType.DialogMessageReceived, processMessage);
                Office.context.ui.messageParent(somevalue);
            });

}

Besides that the processMessage call back never gets triggered, wondering why?

Guys any feedback would be helpful.

Thanks


Solution

  • Office.context.ui.displayDialogAsync must be called from the host page and Office.context.ui.messageParent must be called from the Dialog box.

    This should be on the host page :

    var dialog;    
    Office.context.ui.displayDialogAsync(url,
        {height: 40, width: 40}, function (result) {
             dialog = result.value;
                 dialog.addEventHandler(Office.EventType.DialogMessageReceived, 
                     function(somevalue){ 
                         console.log(somevalue);});
        });
    

    This should be on the Dialog Box :

    Office.initialize = function (reason) {
        $(document).ready(function () {
                Office.context.ui.messageParent(somevalue);
        }
    }
    

    in your manifest, must have all the domains being accessed with "https".

    1. The URL uses the HTTPS protocol. This is mandatory for all pages loaded in a dialog box, not just the first page loaded.
    2. The dialog box's domain is the same as the domain of the host page, which can be the page in a task pane or the function file of an add-in command. This is required: the page, controller method, or other resource that is passed to the displayDialogAsync method must be in the same domain as the host page.

    Please visit here for more info.