Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IAuthenticationRequest.RedirectToProvider is not supposed to return, yet it does

The method DotNetOpenAuth.OpenId.RelyingParty.IAuthenticationRequest.RedirectToProvider() is documented never to return:

Redirects the user agent to the provider for authentication. Execution of the current page terminates after this call.

However, it does return under the latest implementation (3.4.3). I'm using the following code:

using (var relayingParty = new OpenIdRelyingParty())
{
  var response = relayingParty.GetResponse();

  if (response == null)
  {
    // Stage 2: user submitting Identifier
    var openId = Request.Form["openId"];
    relayingParty.CreateRequest(openId).RedirectToProvider();

    throw new Exception("Never gets here");
  }

  ...
}

(The line with "Never gets here" is reached). I need to return an ActionResult from this method ...

  1. Is this a known bug?
  2. Is there a aorkaround? Should I return EmptyResult?

As far as I understand this is a bug - I submitted it in the project issue tracker.

like image 392
ripper234 Avatar asked Apr 27 '10 19:04

ripper234


1 Answers

Since you're using ASP.NET MVC, you should use this code:

using DotNetOpenAuth.Messaging; // required for the extension method to work

    return relyingParty.CreateRequest(openid).RedirectingResponse.AsActionResult();

Apparently ASP.NET usually throws an exception as a result of the RedirectToProvider() call, but not always. But the above code will work and is more MVC friendly.

like image 194
Andrew Arnott Avatar answered Oct 14 '22 20:10

Andrew Arnott