none
Task Pane App is unable to read it's own cookies when reloaded RRS feed

  • Question

  • This issue is driving me insane and I can find traces on the interwebs of other people with more or less the same problem, but no fix... Found two issues on this forum that seem similar/related so far:

    http://social.msdn.microsoft.com/Forums/office/en-US/2cc937cd-b5e5-4ecd-99ce-daef7b595513/task-pane-app-error-webpage-has-expired-issue-with-the-apps-for-office-browser-help-needed
    http://social.msdn.microsoft.com/Forums/office/en-US/f38ee59f-4f77-443c-804a-54424d25b7da/unable-to-access-cookies-object-in-redirectaccessaspx-in-outlook-2013

    So, my problem is this. I've created a Task Pane App for office that connects to a SharePoint 365 site to retrieve some data. To do this I've used OAuth with the server code running on an Azure site and, registered everything with the correct URL, ClientID, ClientSecret etc etc. I've been following these articles:

    http://blogs.msdn.com/b/donovanf/archive/2013/01/10/introduction-to-building-apps-for-office-on-windows-azure-web-sites.aspx
    http://code.msdn.microsoft.com/office/SharePoint-2013-Use-OAuth-47872a28
    http://msdn.microsoft.com/en-us/library/office/apps/jj687470.aspx
    http://msdn.microsoft.com/en-us/library/jj687470.aspx

    When I run the app (from the Azure site, not localhost) inside Word 2013 I'm prompted to trust the app and then it does it's OAuth magic by sending tokens back and fort and I'm returned to the default page of my app where the data from SharePoint is indeed retrieved. The TokenHelper class then saves the refresh token in a cookie.

    I added another page to the app that does not redirect to SharePoint for authentication, but retrieves the refresh token from the cookie and uses that to get a new access token. This also works as expected, retrieving the data from SharePoint, and I can go back and forth between the two pages without getting another "do-you-trust-this-app-redirect".

    Now I close Word and reopen it with the same app, and instead of reading the refresh token from the cookie and getting another access token I am again redirected to the "do-you-trust-this-app-redirect" page... This even happens without closing Word when I right-click the app and choose Reload. In fact the Request.Cookies collection is empty. The cookies are set to expire in a month, and I'm using the OOTB code from Microsoft's sample.

    And here comes the really funky part... If I access the app directly from the browser (same URL that the task pane is using) it has no problems reading the cookie and getting the data without asking me (yet again) to trust the app. I can even close the browser and reopen it, and it still works. This is the behavior I was expecting with a "persistent" cookie.

    So why is the IE running inside Word behaving differently from the IE running on my desktop, and how do I get it to read the cookie it just created a minute ago?

    In one of the theads I linked to at the top the user  Tyler2x4 says "But cookies do in fact work in the office browser. I built a code sample a few weeks ago that makes use of them in both asp.net and javascript. It also used oauth 1.0 (DotNetOpenAuth.Microsoft.Aspnet) and worked fine." but leaves little clues as to how/why this worked. DotNetOpenAuth seems like overkill for my needs when all the other code is already working, and I don't really want to spend another couple of days figuring out how to make it fit into this app when all I want is for IE-In-Word to read my cookie...


    "Man Will Never Be Free Until The Last King Is Strangled With The Entrails Of The Last Priest"




    • Edited by DrLeary Monday, September 16, 2013 7:56 PM
    Monday, September 16, 2013 7:53 PM