में ASP.Net सदस्यता के साथ OpenId एकीकृत करने के लिए मैं कैसे MVC में OpenId परीक्षण करने के लिए MVC स्टोरफ्रंट से निम्नलिखित कोड का उपयोग कर रहा हूँ। कैसे मैं इसे अपने ASP.Net सदस्यता के साथ एकीकृत तो मैं भूमिकाओं का उपयोग कर सकते हैं और मेरे तालिकाओं में उपयोगकर्ता के लिए एक उपयोगकर्ता नाम सहेज सकता हूँ? मेरा मानना है कि एसओ भी इसी तरह का उपयोग कर रहा है।MVC
public ActionResult OpenIdLogin()
{
string returnUrl = VirtualPathUtility.ToAbsolute("~/");
var openid = new OpenIdRelyingParty();
var response = openid.GetResponse();
if (response == null)
{
// Stage 2: user submitting Identifier
Identifier id;
if (Identifier.TryParse(Request["openid_identifier"], out id))
{
try
{
IAuthenticationRequest req = openid.CreateRequest(Request["openid_identifier"]);
var fetch = new FetchRequest();
//ask for more info - the email address
var item = new AttributeRequest(WellKnownAttributes.Contact.Email);
item.IsRequired = true;
fetch.Attributes.Add(item);
req.AddExtension(fetch);
return req.RedirectingResponse.AsActionResult();
}
catch (ProtocolException ex)
{
ViewData["Message"] = ex.Message;
return View("Logon");
}
}
else
{
ViewData["Message"] = "Invalid identifier";
return View("Logon");
}
}
else
{
// Stage 3: OpenID Provider sending assertion response
switch (response.Status)
{
case AuthenticationStatus.Authenticated:
var fetch = response.GetExtension<FetchResponse>();
string name = response.FriendlyIdentifierForDisplay;
if (fetch != null)
{
IList<string> emailAddresses = fetch.Attributes[WellKnownAttributes.Contact.Email].Values;
string email = emailAddresses.Count > 0 ? emailAddresses[0] : null;
//don't show the email - it's creepy. Just use the name of the email
name = email.Substring(0, email.IndexOf('@'));
}
else
{
name = name.Substring(0, name.IndexOf('.'));
}
//FormsAuthentication.SetAuthCookie(name, false);
SetCookies(name, name);
AuthAndRedirect(name, name);
if (!string.IsNullOrEmpty(returnUrl))
{
return Redirect(returnUrl);
}
else
{
return RedirectToAction("Index", "Home");
}
case AuthenticationStatus.Canceled:
ViewData["Message"] = "Canceled at provider";
return View("Logon");
case AuthenticationStatus.Failed:
ViewData["Message"] = response.Exception.Message;
return View("Logon");
}
}
return new EmptyResult();
}
ActionResult AuthAndRedirect(string userName, string friendlyName)
{
string returnUrl = Request["ReturnUrl"];
SetCookies(userName, friendlyName);
if (!String.IsNullOrEmpty(returnUrl))
{
return Redirect(returnUrl);
}
else
{
return RedirectToAction("Index", "Home");
}
}
मैं एक नए कार्यान्वयन के साथ खेल रहा हूं इसलिए, मैं एएसपी.NET सदस्यता से विशेष रूप से विवाहित नहीं हूं। क्या आप नमूना कोड के साथ सुझाव दे सकते हैं कि आपने इसका उल्लेख कैसे किया है? – Picflight
मैं नमूना कोड के लिए यहां "मुझे भी" छोड़ दूंगा। किसी के बारे में पता है? –
सभी नमूनों और परियोजना टेम्पलेट्स कि DotNetOpenAuth साथ जहाज जिस तरह से मैंने कहा है। –