我正在尝试使用 Mozilla Persona 登录做一个示例应用程序,但在示例代码中出现错误。
代码
public class AuthController : Controller
{
[HttpPost]
public ActionResult Login(string assertion)
{
if (assertion == null)
{
// The 'assertion' key of the API wasn't POSTED. Redirect,
// or whatever you'd like, to try again.
return RedirectToAction("Index", "Home");
}
using (var web = new WebClient())
{
// Build the data we're going to POST.
var data = new NameValueCollection();
data["assertion"] = assertion;
data["audience"] = "https://example.com:443"; // Use your website's URL here.
// POST the data to the Persona provider (in this case Mozilla)
var response = web.UploadValues("https://verifier.login.persona.org/verify", "POST", data);
var buffer = Encoding.Convert(Encoding.GetEncoding("iso-8859-1"), Encoding.UTF8, response);
// Convert the response to JSON.
var tempString = Encoding.UTF8.GetString(buffer, 0, response.Length);
var reader = new JsonReader();
dynamic output = reader.Read(tempString);
if (output.status == "okay")
{
string email = output.email; // Since this is dynamic, convert it to string.
FormsAuthentication.SetAuthCookie(email, true);
return RedirectToAction("Index", "Home");
}
// Could not log in, do something else.
return RedirectToAction("Index", "Home");
}
}
}
错误
我在下面的行中收到一个错误,通知构造函数不能接受 0 个参数。好的,这很清楚。但是我从Mozilla Persona获得了这段代码。
var reader = new JsonReader();
更新
我在下面的代码中遇到了同样的错误
var reader = new JsonFx.Json.JsonReader();
有人可以帮助我吗?
我在 stackoverflow 中发现了一些问题,就像这个你可以看到相同的代码的问题。