Reputation: 9011
extention method
AsActionResult()
does not work. I get string "DotNetOpenAuth.Messaging.OutgoingWebResponseActionResult" to response instead of redirect to provider. namespace
using DotNetOpenAuth.Messaging;
is included. Where is problem?
[ADDED] my code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DotNetOpenAuth.Messaging;
using DotNetOpenAuth.OpenId;
using DotNetOpenAuth.OpenId.RelyingParty;
using System.Web.Security;
public class UserController : Controller
{
private static OpenIdRelyingParty openIdProvider = new OpenIdRelyingParty();
public ActionResult Authenticate(string userOpenId)
{
// Ответ с сайта провайдера.
IAuthenticationResponse response = openIdProvider.GetResponse();
// response равен null, если запроса на OpenID провайдер мы не делали.
if (response == null)
{
Identifier id;
// Пытаемся распарсить OpenID клиента.
if (Identifier.TryParse(userOpenId, out id))
{
try
{
// Делаем редирект на сайт провайдера OpenID
return
openIdProvider
.CreateRequest(userOpenId)
.RedirectingResponse
.AsActionResult(); // Расширение для MVC
}
catch (ProtocolException ex)
{
ViewData["Message"] = ex.Message;
}
}
else
{
// Не корректный OpenID клиента
ViewData["Message"] = "Invalid identifier";
}
return View("Login");
}
else
{
// Ответ с сайта провайдера OpenID
switch (response.Status)
{
// Успешная аутентификация
case AuthenticationStatus.Authenticated:
{
Session["FriendlyIdentifier"] = response.FriendlyIdentifierForDisplay;
// Аутентифицированы по cookies.
FormsAuthentication.SetAuthCookie(response.ClaimedIdentifier, false);
return RedirectToAction("Index", "Home");
}
// Аутентификация была отменена пользователем
case AuthenticationStatus.Canceled:
{
ViewData["Message"] = "Canceled at provider";
return View("Login");
}
// Аутентификация не удалась из за ошибки.
case AuthenticationStatus.Failed:
{
ViewData["Message"] = response.Exception.Message;
return View("Login");
}
// При прочих, делаем редирект на главную.
default:
{
return RedirectToAction("Index", "Home");
}
}
}
}
}
Upvotes: 2
Views: 983
Reputation: 9011
I found solution - need to check web.config and be sure, that all libraries compiled to .NET 3.0. Correct keys:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly xmlns="">
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="2.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
incorrect:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
<dependentAssembly xmlns="">
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="2.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
Upvotes: 3