0

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

Mani
  • 65
  • 5

2 Answers2

0

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.

  • I can successfully send message back to parent/task pane. Thanks for your comment. However, I cant figure out how can I read tokens from the dialog window which loads the redirected uri containing it. – Mani Aug 02 '20 at 05:56
0

As I am new to web development, so it was a basic/easy solution. I created html pages within outlook web add-in as redirect URI that we specify in Azure app to send tokens to. Then using JavaScript, I can parse URL which contains access token.

Mani
  • 65
  • 5