Menu Home

Office 365 API Tools August 2014 Update and RedirectRequiredException

It’s really nice to see the cadence Microsoft is getting up to with their release cycle. Yesterday a new version of the Office 365 API Tools (1.1.728) was release that improves on the previous releases (not so much if you are using it in a web application, it seems like most improvements are for the client libraries and for phonegap).

Nevertheless I just took it for a quick spin in a MVC application as I have done with with the previous releases too. The first thing you will notice, if you try to add e.g. the MailApiSample to a simple MVC list view controller, is that you get an exception like this
[RedirectRequiredException: The browser must be redirected to a new URL.]
Microsoft.Office365.OAuth.DiscoveryContext`1.RedirectForResourceAuthorizationCode(String resourceId)

What the eck, they changed how the auth-flow is working. I’m not sure I agree with this change of using Exceptions to handle the typical Auth-flow, but I will have to spend some more time investigating what else have been changed before I make my verdict.

Anyways in order to correctly sign in you have to wrap your call to the MailApiSample (or MyFiles) in a try/catch and handle the RedirectRequiredException so my simple mail controller looks like this.

   
using Microsoft.Office365.OAuth;
using System.Threading.Tasks;
using System.Web.Mvc;

public class MailController : Controller
    {
        // GET: Mail
        public async Task<ActionResult> Index()
        {
            try
            {
                var messages = await MailApiSample.GetMessages();
                return View(messages);
            }
            catch (RedirectRequiredException ex)
            {
                return Redirect(ex.RedirectUri.ToString());
            }
            
        }
    }

If you want to read more check Chakkaradeep Chandran’s blog post and the official annoucement. It sounds like we are closing in on a non-preview version, I’m looking forward to that!

Categories: Office SharePoint

Tagged as:

Simon J.K. Pedersen

2 replies

  1. Thanks for the post Simon. I am new to this, so please excuse me if the question sounds dumb…I tried to catch the exception, but the sample above doesn’t compile. RedirectRequiredException is an unknown type…is there a ‘using’ that I am missing? Here’re the namespaces that I am referencing:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    using Microsoft.Office365.Exchange;
    using Microsoft.Office365;
    using System.Threading.Tasks;

    Thank you…Murali

  2. Hi Murali, I updated the sample to include the required using statements, sorry for the inconvenience

Leave a Reply

Your email address will not be published. Required fields are marked *