benyblack
@
۱۴ مرداد ۱۳۸۹-۱۷:۱۵
OpenId & MVC
اما برای سریعتر انجام شدن کار میشه از سرویس هایی نظیر
janrain استفاده کنید. برای این کار اول این کلاس ها رو به پروژه اضافه کنید (
دانلود)
اما کنترلر:
public ActionResult Login(string token) {
if (string.IsNullOrEmpty(token)) {
return new EmptyResult();
} else {
IRpxLogin rpxLogin = new RpxLogin("your token");
try {
RpxProfile profile = rpxLogin.GetProfile(token);
//todo: validate username
string m = Membership.GetUserNameByEmail(profile.Email);
if (m == null)
return RedirectToAction("Register");
//else issue ticket and redirect to home or callback url
IssueAuthTicket(profile.Email, profile.DisplayName, false);
FormsAuthentication.SetAuthCookie(profile.DisplayName, false);
} catch (RpxException) {
return RedirectToAction("LogOn", "Account");
}
return RedirectToAction("Index", "Home");
}
}