public ActionResult SignIn() { var openid = new OpenIdRelyingParty(); var response = openid.GetResponse(); if (response != null) { switch (response.Status) { case AuthenticationStatus.Authenticated: var claimsResponse = response.GetExtension<ClaimsResponse>(); FormsAuthentication.SetAuthCookie(claimsResponse.Email, true); return RedirectToAction("Index", "Member"); case AuthenticationStatus.Canceled: ModelState.AddModelError("loginIdentifier", "Login was cancelled at the provider"); break; case AuthenticationStatus.Failed: ModelState.AddModelError("loginIdentifier", "Login failed using the provided OpenID identifier"); break; } } return View(); }
/// <summary> /// Authenicates a user based on the information in the HTTP request. /// </summary> /// <returns></returns> public override GraywulfPrincipal Authenticate() { // Get OpenID provider's response from the http context using (var openid = new OpenIdRelyingParty()) { var response = openid.GetResponse(); // TODO: figure out which OpenID provider sent the response // and associate with the right authenticator if (response != null) { switch (response.Status) { case AuthenticationStatus.Authenticated: return CreatePrincipal(response); case AuthenticationStatus.Canceled: case AuthenticationStatus.Failed: throw new System.Security.Authentication.AuthenticationException("OpenID authentication failed.", response.Exception); case AuthenticationStatus.ExtensionsOnly: case AuthenticationStatus.SetupRequired: throw new InvalidOperationException(); default: throw new NotImplementedException(); } } return null; } }
protected void Page_Load(object sender, EventArgs e) { using (var openid = new OpenIdRelyingParty()) { // In order to receive the UIRequest as a response, we must register a custom extension factory. openid.ExtensionFactories.Add(new UIRequestAtRelyingPartyFactory()); var response = openid.GetResponse(); if (response == null) { // Submit an OpenID request which Google must reply to immediately. // If the user hasn't established a trust relationship with this site yet, // Google will not give us the user identity, but they will tell us whether the user // at least has an active login session with them so we know whether to promote the // "Log in with Google" button. IAuthenticationRequest request = openid.CreateRequest("https://www.google.com/accounts/o8/id"); request.AddExtension(new UIRequest { Mode = UIModeDetectSession }); request.Mode = AuthenticationRequestMode.Immediate; request.RedirectToProvider(); } else { if (response.Status == AuthenticationStatus.Authenticated) { this.YouTrustUsLabel.Visible = true; } else if (response.Status == AuthenticationStatus.SetupRequired) { // Google refused to authenticate the user without user interaction. // This is either because Google doesn't know who the user is yet, // or because the user hasn't indicated to Google to trust this site. // Google uniquely offers the RP a tip as to which of the above situations is true. // Figure out which it is. In a real app, you might use this value to promote a // Google login button on your site if you detect that a Google session exists. var ext = response.GetUntrustedExtension<UIRequest>(); this.YouAreLoggedInLabel.Visible = ext != null && ext.Mode == UIModeDetectSession; this.YouAreNotLoggedInLabel.Visible = !this.YouAreLoggedInLabel.Visible; } } } }
public void IsValidLogin(Uri serviceUri) { var result = false; var openid = new OpenIdRelyingParty(); if (openid.GetResponse() == null) { // Stage 2: user submitting Identifier openid.CreateRequest(HttpRequest.Request.Form["openid_identifier"]).RedirectToProvider(); } else { // Stage 3: OpenID Provider sending assertion response switch (openid.Response.Status) { case AuthenticationStatus.Authenticated: FormsAuthenticationProvider.RedirectFromLoginPage(openid.Response.ClaimedIdentifier, false); break; case AuthenticationStatus.Canceled: ViewData["Message"] = "Canceled at provider"; RenderView("Login"); break; case AuthenticationStatus.Failed: ViewData["Message"] = openid.Response.Exception.Message; RenderView("Login"); break; } } }
// // GET: /LogOn/ public ActionResult LogOn() { var openid = new OpenIdRelyingParty(); var response = openid.GetResponse(); if (response != null) { switch (response.Status) { case AuthenticationStatus.Authenticated: var fetch = response.GetExtension<FetchResponse>(); if (fetch != null) { foreach (var attribute in fetch.Attributes) { ViewData.Add(attribute.TypeUri, string.Join("|", attribute.Values)); } } //response.ClaimedIdentifier //return RedirectToAction("LogOn"); break; case AuthenticationStatus.Canceled: ModelState.AddModelError("loginIdentifier", "Login was cancelled at the provider"); break; case AuthenticationStatus.Failed: ModelState.AddModelError("loginIdentifier", "Login failed using the provided OpenID identifier"); break; } } return View(); }
public ActionResult Login() { var openid = new OpenIdRelyingParty(); IAuthenticationResponse response = openid.GetResponse(); if (response != null) { switch (response.Status) { case AuthenticationStatus.Authenticated: var user = EnsureUserExists(response); FormsAuthentication.RedirectFromLoginPage( user.email, false); break; case AuthenticationStatus.Canceled: ModelState.AddModelError("loginIdentifier", "Login was cancelled at the provider"); break; case AuthenticationStatus.Failed: ModelState.AddModelError("loginIdentifier", "Login failed using the provided OpenID identifier"); break; } } return View(); }
public ActionResult LogOn(string from) { var openid = new OpenIdRelyingParty(); IAuthenticationResponse response = openid.GetResponse(); if (response != null) { switch (response.Status) { case AuthenticationStatus.Authenticated: var sreg = response.GetExtension<ClaimsResponse>(); if (sreg != null) { Session.Add("Email", sreg.Email); Session.Add("FullName", sreg.FullName); } FormsAuthentication.RedirectFromLoginPage(response.ClaimedIdentifier, false); break; case AuthenticationStatus.Canceled: ModelState.AddModelError("loginIdentifier", "Login was cancelled at the provider"); break; case AuthenticationStatus.Failed: ModelState.AddModelError("loginIdentifier", "Login failed using the provided OpenID identifier"); break; } } return View(); }
public ActionResult Authenticate(string returnUrl) { var rp = new OpenIdRelyingParty(); var response = rp.GetResponse(); if (response != null) { switch (response.Status) { case AuthenticationStatus.Authenticated: // Make sure we have a user account for this guy. string identifier = response.ClaimedIdentifier; // convert to string so LinqToSQL expression parsing works. if (MvcApplication.DataContext.Users.FirstOrDefault(u => u.OpenIDClaimedIdentifier == identifier) == null) { MvcApplication.DataContext.Users.InsertOnSubmit(new User { OpenIDFriendlyIdentifier = response.FriendlyIdentifierForDisplay, OpenIDClaimedIdentifier = response.ClaimedIdentifier, }); } FormsAuthentication.SetAuthCookie(response.ClaimedIdentifier, false); return this.Redirect(returnUrl ?? Url.Action("Index", "Home")); default: ModelState.AddModelError(string.Empty, "An error occurred during login."); break; } } return this.View("LogOn"); }
public ActionResult Login() { var openId = new OpenIdRelyingParty(); var response = openId.GetResponse(); if (response != null) { switch (response.Status) { case AuthenticationStatus.Authenticated: var user = BlogService.GetOrCreateUser(response); return FinishAuthentication(user); case AuthenticationStatus.Canceled: throw new Exception("Login was cancelled at the provider"); case AuthenticationStatus.Failed: throw new Exception("Login failed using the provided OpenID identifier"); default: throw new NotImplementedException(); } } return View(GetViewModel()); }
/// <summary> /// Authenicates a user based on the information in the HTTP request. /// </summary> /// <returns></returns> public override void Authenticate(AuthenticationRequest request, AuthenticationResponse response) { // Only execute the authentication if the user is not known yet if (response.Principal == null) { // Get OpenID provider's response from the http context using (var openid = new OpenIdRelyingParty()) { var openIDResponse = openid.GetResponse(); // TODO: figure out which OpenID provider sent the response // and associate with the right authenticator if (response != null) { switch (openIDResponse.Status) { case AuthenticationStatus.Authenticated: response.SetPrincipal(CreatePrincipal(openIDResponse)); break; case AuthenticationStatus.Canceled: case AuthenticationStatus.Failed: throw new System.Security.Authentication.AuthenticationException("OpenID authentication failed.", openIDResponse.Exception); // TODO case AuthenticationStatus.ExtensionsOnly: case AuthenticationStatus.SetupRequired: throw new InvalidOperationException(); default: throw new NotImplementedException(); } } } } }
void DoLoad() { OpenIdRelyingParty openid = new OpenIdRelyingParty(); var response = openid.GetResponse(); if (response == null) return; switch (response.Status) { case AuthenticationStatus.Authenticated: var fetch = response.GetExtension<FetchResponse>(); Session["claim"] = response.ClaimedIdentifier; Session["user"] = GetUserDetail(fetch); // This is where you would look for any OpenID extension responses included // in the authentication assertion. //var claimsResponse = response.GetExtension<ClaimsResponse>(); //Database.ProfileFields = claimsResponse; // Store off the "friendly" username to display -- NOT for username lookup //Database.FriendlyLoginName = response.FriendlyIdentifierForDisplay; // Use FormsAuthentication to tell ASP.NET that the user is now logged in, // with the OpenID Claimed Identifier as their username. FormsAuthentication.RedirectFromLoginPage(response.ClaimedIdentifier, false); break; case AuthenticationStatus.Canceled: break; case AuthenticationStatus.Failed: break; } LabelStatus.Text = string.Format("Status : {0}", response.Status); }
public ActionResult LogOn() { var openid = new OpenIdRelyingParty(); IAuthenticationResponse response = openid.GetResponse(); var page = HttpContext.Items["page"] = "/"; if (response != null) { switch (response.Status) { case AuthenticationStatus.Authenticated: FormsAuthentication.SetAuthCookie(response.GetExtension<ClaimsResponse>().Email, false); return Redirect("~" + response.GetCallbackArgument("redirectPage")); break; case AuthenticationStatus.Canceled: ModelState.AddModelError("loginIdentifier", "Login was cancelled at the provider"); break; case AuthenticationStatus.Failed: ModelState.AddModelError("loginIdentifier", "Login failed using the provided OpenID identifier"); break; } } return View(); }
public ActionResult LogOn() { var openid = new OpenIdRelyingParty(); IAuthenticationResponse response = openid.GetResponse(); if (response != null) { switch (response.Status) { case AuthenticationStatus.Authenticated: FormsAuthentication.SetAuthCookie(accountRepository.Login(response.ClaimedIdentifier).ToString(), true); return new RedirectResult("/", false); case AuthenticationStatus.Canceled: ModelState.AddModelError("loginIdentifier", "Login was cancelled at the provider"); break; case AuthenticationStatus.Failed: ModelState.AddModelError("loginIdentifier", "Login failed using the provided OpenID identifier"); break; } } return View(); }
// // GET: /Home/ //STEAM_0:0:68926576 //SteamWebAPI.SetGlobalKey("CFDCF16D4EC9D68762FBE9C61B43892D"); //vmykel //wheniwasyourman public ActionResult Index() { OpenIdRelyingParty openid = new OpenIdRelyingParty(); OpenIdLogin openlog = new OpenIdLogin(); openid.SecuritySettings.AllowDualPurposeIdentifiers = true; IAuthenticationResponse response = openid.GetResponse(); if (response != null) { string regex = Request.QueryString["openid.identity"]; //string youareel= "http://steamcommunity.com/openid/id/76561198131281243"; string[] str = regex.Split('/'); string id = str[5]; Session["user"] = id; FormsAuthentication.SetAuthCookie(id, false); if(!User.Identity.IsAuthenticated) { return RedirectToAction("Index"); } if (User.Identity.IsAuthenticated) { return RedirectToAction("Index","Account"); } } if (User.Identity.IsAuthenticated) { return RedirectToAction("Index", "Account"); } return View(); }
public ActionResult Index() { ViewData["Authenticated"] = "FALSE"; using (OpenIdRelyingParty openid = new OpenIdRelyingParty()) { var response = openid.GetResponse(); if (response != null) { switch (response.Status) { case AuthenticationStatus.Authenticated: ViewData["Authenticated"] = "TRUE"; break; case AuthenticationStatus.Canceled: ViewData["Authenticated"] = "Cancelled"; break; case AuthenticationStatus.Failed: ViewData["Authenticated"] = "FAILED"; break; } } } return View(); }
public ActionResult Index() { var openId = new OpenIdRelyingParty(); IAuthenticationResponse response = openId.GetResponse(); // if this is a roundtrip and we got something back from the provider... if (response != null) { switch (response.Status) { case AuthenticationStatus.Authenticated: { FormsAuthentication.RedirectFromLoginPage(response.ClaimedIdentifier, false); break; } case AuthenticationStatus.Canceled: { ModelState.AddModelError("loginIdentifier", "Login was cancelled at the provider"); break; } case AuthenticationStatus.Failed: { ModelState.AddModelError("loginIdentifier", "Login failed at the provider"); break; } } } return View(); }
public ActionResult LogOnCallback(string returnUrl) { OpenIdRelyingParty openid = new OpenIdRelyingParty(); var response = openid.GetResponse(); if (response == null) { return RedirectToAction("Error", new { returnUrl = returnUrl, error = "No authentication response" }); } if (response.Status != AuthenticationStatus.Authenticated) { return RedirectToAction("Error", new { returnUrl = returnUrl, error = "Response status is not Authenticated" }); } var fetch = response.GetExtension<FetchResponse>(); if (fetch == null) { return RedirectToAction("Error", new { returnUrl = returnUrl, error = "No fetch response" }); } string email = fetch.GetAttributeValue(WellKnownAttributes.Contact.Email); if (string.IsNullOrWhiteSpace(email)) { return RedirectToAction("Error", new { returnUrl = returnUrl, error = "Response Email is empty" }); } if (!email.EndsWith(EmailSuffix)) { return RedirectToAction("Error", new { returnUrl = returnUrl, error = "Only emails ended with " + EmailSuffix + " are allowed" }); } var username = email.Substring(0, email.Length - EmailSuffix.Length); FormsAuthentication.SetAuthCookie(username, true); Session[SessionRolesKey] = new string[0]; var user = RavenSession.Query<User>().Where(u => u.UserName == username).FirstOrDefault(); log.Debug("User {0} found: {1}", username, user != null); if (user != null) { log.Dump(LogLevel.Debug, user, "RavenDB User"); Session[SessionRolesKey] = user.Roles ?? new string[0]; } if (!string.IsNullOrWhiteSpace(returnUrl) && Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/") && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\")) { return Redirect(returnUrl); } else { return RedirectToAction("Index", "Home"); } }
/// <summary> /// Action Results for Index, uses DotNetOpenAuth for creating OpenId Request with Intuit /// and handling response recieved. /// </summary> /// <param name="sender">Sender of the event.</param> /// <param name="e">Event Args.</param> protected void Page_Load(object sender, EventArgs e) { //OpenId Relying Party OpenIdRelyingParty openid = new OpenIdRelyingParty(); var openIdIdentifier = ConfigurationManager.AppSettings["openid_identifier"]; var response = openid.GetResponse(); if (response == null) { // Stage 2: user submitting Identifier Identifier id; if (Identifier.TryParse(openIdIdentifier, out id)) { try { IAuthenticationRequest request = openid.CreateRequest(openIdIdentifier); FetchRequest fetch = new FetchRequest(); fetch.Attributes.Add(new AttributeRequest(WellKnownAttributes.Contact.Email)); fetch.Attributes.Add(new AttributeRequest(WellKnownAttributes.Name.FullName)); request.AddExtension(fetch); request.RedirectToProvider(); } catch (ProtocolException ex) { throw ex; } } } else { if (response.FriendlyIdentifierForDisplay == null) { Response.Redirect("/OpenIdHandler.aspx"); } // Stage 3: OpenID Provider sending assertion response Session["FriendlyIdentifier"] = response.FriendlyIdentifierForDisplay; FetchResponse fetch = response.GetExtension<FetchResponse>(); if (fetch != null) { Session["OpenIdResponse"] = "True"; Session["FriendlyEmail"] = fetch.GetAttributeValue(WellKnownAttributes.Contact.Email); Session["FriendlyName"] = fetch.GetAttributeValue(WellKnownAttributes.Name.FullName); } //Check if user disconnected from the App Center if (Request.QueryString["disconnect"] != null && Request.QueryString["disconnect"].ToString(CultureInfo.InvariantCulture) == "true") { Session["Flag"] = true; Response.Redirect("CleanupOnDisconnect.aspx"); } else { Response.Redirect("Default.aspx"); } } }
public ActionResult OpenID() { ViewData["message"] = "You are not logged in"; var openid = new OpenIdRelyingParty(); IAuthenticationResponse response = openid.GetResponse(); if (response != null && response.Status == AuthenticationStatus.Authenticated) ViewData["message"] = "Success! Identifier: " + response.ClaimedIdentifier; return View("OpenID"); }
public ActionResult Authenticate(string returnUrl) { var openid = new OpenIdRelyingParty(); var response = openid.GetResponse(); if (response == null) { // Stage 2: user submitting Identifier Identifier id; if (Identifier.TryParse(Request.Form["openid_identifier"], out id)) { try { var req = openid.CreateRequest(id); var fetch = new FetchRequest(); //ask for more info - the email address //no guarantee you'll get it back :) var email = new AttributeRequest(WellKnownAttributes.Contact.Email); email.IsRequired = true; fetch.Attributes.Add(email); req.AddExtension(fetch); return req.RedirectingResponse.AsActionResult(); } catch (ProtocolException ex) { ViewData["Message"] = ex.Message; return View("Login"); } } else { ViewData["Message"] = "Invalid identifier"; return View("Login"); } } else { // Stage 3: OpenID Provider sending assertion response switch (response.Status) { case AuthenticationStatus.Authenticated: //They're in there... var fetch = response.GetExtension<FetchResponse>(); string email = null; if (fetch != null) { IList<string> emailAddresses = fetch.Attributes[WellKnownAttributes.Contact.Email].Values; email = emailAddresses.Count > 0 ? emailAddresses[0] : null; } var friendly = email ?? response.FriendlyIdentifierForDisplay; return AuthAndRedirect(friendly, response.ClaimedIdentifier); case AuthenticationStatus.Canceled: ViewData["Message"] = "Canceled at provider"; return View("Login"); case AuthenticationStatus.Failed: ViewData["Message"] = response.Exception.Message; return View("Login"); } } return new EmptyResult(); }
internal static string SignIn(Guid userDetailsPageId) { string errorMessage = string.Empty; using (var openid = new OpenIdRelyingParty()) { //fix wrong URI, add PathInfo HttpContext.Current.RewritePath(HttpContext.Current.Request.RawUrl); IAuthenticationResponse response = openid.GetResponse(); if (response == null) { //request string openIDIdentifier = HttpContext.Current.Request.Form["openid_identifier"]; if (!string.IsNullOrEmpty(openIDIdentifier)) { IAuthenticationRequest request = openid.CreateRequest(openIDIdentifier); var claims = new ClaimsRequest(); claims.Email = DemandLevel.Require; claims.Nickname = DemandLevel.Require; claims.FullName = DemandLevel.Require; claims.Country = DemandLevel.Require; request.AddExtension(claims); //small fix for request.RedirectToProvider(); string location = request.RedirectingResponse.Headers["Location"]; HttpContext.Current.Response.Redirect(location, false); } } else { //response switch (response.Status) { case AuthenticationStatus.Authenticated: HandleSuccessfulSignIn(response, userDetailsPageId); break; case AuthenticationStatus.Canceled: errorMessage = "Login was cancelled at the provider."; break; case AuthenticationStatus.Failed: errorMessage = "Login failed at the provider."; break; case AuthenticationStatus.SetupRequired: errorMessage = "The provider requires setup."; break; default: errorMessage = "Login failed."; break; } } } return errorMessage; }
// // Get: /Authentication/Login/openid public ActionResult Authenticate() { 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"); } // Stage 3: OpenID Provider sending assertion response switch (response.Status) { case AuthenticationStatus.Authenticated: var claimedIdentifier = response.ClaimedIdentifier; var user = Users.FindByOpenId(claimedIdentifier); if (user != null) { // login return RedirectFromLoginPage(user); } // register var username = response.FriendlyIdentifierForDisplay; user = new User { Name = username, OpenId = claimedIdentifier, Reputation = 1, SignupDate = DateTime.Now }; Users.Save(user); return RedirectFromLoginPage(user); case AuthenticationStatus.Canceled: ViewData["Message"] = "Canceled at provider"; // todo return View("Login"); case AuthenticationStatus.Failed: ViewData["Message"] = response.Exception.Message; // todo return View("Login"); default: throw new Exception("Unknown status"); } } }
/// <summary> /// Logon Action. /// </summary> /// <returns>Logon View</returns> public virtual ActionResult LogOn() { LogOn model = new LogOn(); var openid = new OpenIdRelyingParty(); IAuthenticationResponse response = openid.GetResponse(); if (response != null) { switch (response.Status) { case AuthenticationStatus.Authenticated: var email = string.Empty; var claimsResponse = response.GetExtension<ClaimsResponse>(); if (claimsResponse != null) { email = claimsResponse.Email; } if (!string.IsNullOrEmpty(email)) { var guid = this.accountService.NewAccountStep1(response.ClaimedIdentifier, email); if (this.accountService.NeedsAdditionInformation(guid)) { return this.RedirectToAction(this.Actions.LogOnStep2(guid, email)); } else { Account a = this.accountService.GetByPrivateGuid(guid); this.IssueAuthTicket(new UserState() { PrivateGuid = a.PrivateGuid, EmailAddress = a.EmailAddress, DisplayName = a.DisplayName }, true); } return this.RedirectToAction(MVC.Home.Index()); } else { model.ShowNoEmailError = true; } break; case AuthenticationStatus.Canceled: model.ShowCancelledError = true; break; case AuthenticationStatus.Failed: model.ShowFailedError = true; break; } } // fall through to show login view, not a return from the openid provider. return this.View(model); }
protected void Page_Load(object sender, EventArgs e) { OpenIdRelyingParty rp = new OpenIdRelyingParty(); var response = rp.GetResponse(); // if this isn't a postback and it isn't an oauth response, push them over to google to login... // unless you want to give them a button or option to login if (response == null && !IsPostBack) GoogleLogin(); // process oauth response if (response != null) { switch (response.Status) { case AuthenticationStatus.Authenticated: FetchResponse fetch = response.GetExtension<FetchResponse>(); string email = fetch.Attributes["http://axschema.org/contact/email"].Values[0].ToString(); string firstname = fetch.Attributes["http://axschema.org/namePerson/first"].Values[0].ToString(); string lastname = fetch.Attributes["http://axschema.org/namePerson/last"].Values[0].ToString(); string id = response.ClaimedIdentifier.ToString(); // could add a check here to validate user is from a specific domain, like this: //if (!email.EndsWith("@fynydd.com")) // Response.Redirect("onlyfynydd.aspx", true); // put some code here to record the user login // can't use regular auth redirect because we had to double urlencode the return to... //FormsAuthentication.RedirectFromLoginPage(email, false); FormsAuthentication.SetAuthCookie(email, false); string returnurl = FormsAuthentication.DefaultUrl; if (Request["returnurl"] != null) returnurl = Server.UrlDecode(Request["returnurl"].ToString()); if (returnurl.Length ==0) returnurl = "/"; Response.Redirect(returnurl, true); break; case AuthenticationStatus.Canceled: break; case AuthenticationStatus.Failed: break; } } }
public LoginViewModel Execute(LoginInputModel inputModel) { var party = new OpenIdRelyingParty(); var response = party.GetResponse(); var viewModel = new LoginViewModel(); if (response != null && response.Status == AuthenticationStatus.Authenticated) { _authenticationContext.ThisUserHasBeenAuthenticated(response.ClaimedIdentifier, false); viewModel.LoginSuccessful = true; } return viewModel; }
public ActionResult LogOn() { var openid = new OpenIdRelyingParty(); IAuthenticationResponse response = openid.GetResponse(); if (response != null) { var fetchResponse = response.GetExtension<FetchResponse>(); switch (response.Status) { case AuthenticationStatus.Authenticated: var claimedIdentifier = response.ClaimedIdentifier; User user = DocumentSession.Query<User>("UserByClaimedIdentifier").SingleOrDefault(u => u.ClaimedIdentifier.Equals(claimedIdentifier)); if (user == null) { user = new User { FullName = fetchResponse.GetAttributeValue(WellKnownAttributes.Name.FullName), Email = fetchResponse.GetAttributeValue(WellKnownAttributes.Contact.Email), ClaimedIdentifier = claimedIdentifier }; DocumentSession.Store(user); } LoginUser(user); if (string.IsNullOrEmpty(user.FullName)) { return RedirectToAction("Details", "User"); } return RedirectToAction("Index", "Home"); case AuthenticationStatus.Canceled: ModelState.AddModelError("loginIdentifier", "Login was cancelled at the provider"); break; case AuthenticationStatus.Failed: ModelState.AddModelError("loginIdentifier", "Login failed using the provided OpenID identifier"); break; } } return View(); }
public ActionResult Login(string returnUrl) { using (var openid = new OpenIdRelyingParty()) { var response = openid.GetResponse(); if (response == null) { return BeginAuthentication(openid); } else { return EndAuthentication(response, returnUrl); } } }
public ActionResult LogOn() { var openId = new OpenIdRelyingParty(); var response = openId.GetResponse(); if (response == null) { ModelState.AddModelError("loginIdentifier", "Login failed"); TempData["Error"] = "Login failed"; return RedirectToAction("Translate", "Home"); } //http://thenextweb.com/socialmedia/2010/11/04/facebook-connect-oauth-and-openid-the-differences-and-the-future/ //http://developers.facebook.com/docs/authentication/ //http://developers.facebook.com/docs/guides/web/ switch (response.Status) { case AuthenticationStatus.Authenticated: var claimsResponse = response.GetExtension<ClaimsResponse>(); var email = claimsResponse.Email; var fullName = claimsResponse.FullName; var user = Membership.FindUsersByEmail(email).OfType<MembershipUser>().FirstOrDefault(); if (user == null) { Membership.CreateUser(email, "2E2F37C2-79AA-4521-95D8-842B38BB2809", email); using (var context = new Context()) { var translator = context.Translators.FirstOrDefault(t => t.EMail == email) ?? context.Translators.Add(new Translator()); translator.EMail = email; translator.FullName = fullName; context.SaveChanges(); } } FormsAuthentication.SetAuthCookie(email, true); return RedirectToAction("Translate", "Home"); break; case AuthenticationStatus.Canceled: ModelState.AddModelError("loginIdentifier", "Login was cancelled at the provider"); TempData["Error"] = "Login was cancelled at the provider"; break; case AuthenticationStatus.Failed: ModelState.AddModelError("loginIdentifier", "Login failed using the provided OpenID identifier"); TempData["Error"] = "Login failed using the provided OpenID identifier"; break; } return RedirectToAction("Translate", "Home"); }
// // Get: /Authentication/Login/openid public ActionResult Authenticate() { using (var relayingParty = new OpenIdRelyingParty()) { var response = relayingParty.GetResponse(); if (response == null) { // Stage 2: user submitting Identifier var openId = Request.Form["openid_identifier"]; var req = relayingParty.CreateRequest(openId); req.AddExtension(new ClaimsRequest { Email = DemandLevel.Require, FullName = DemandLevel.Require, Nickname = DemandLevel.Request, }); req.RedirectToProvider(); // todo - http://stackoverflow.com/questions/2724455/iauthenticationrequest-redirecttoprovider-is-not-supposed-to-return-yet-it-does throw new Exception("Never gets here"); } // Stage 3: OpenID Provider sending assertion response switch (response.Status) { case AuthenticationStatus.Authenticated: var claimedIdentifier = response.ClaimedIdentifier; return LoginAsUser(claimedIdentifier, response); case AuthenticationStatus.Canceled: ViewData["Message"] = "Canceled at provider"; // todo return View("Login"); case AuthenticationStatus.Failed: ViewData["Message"] = response.Exception.Message; // todo return View("Login"); default: throw new Exception("Unknown status"); } } }
public ActionResult Index(LoginModel log) { OpenIdRelyingParty openid = new OpenIdRelyingParty(); try { IAuthenticationRequest request = openid.CreateRequest("http://steamcommunity.com/openid"); OpenIdLogin openlog = new OpenIdLogin(); openid.SecuritySettings.AllowDualPurposeIdentifiers = true; IAuthenticationResponse response = openid.GetResponse(); return request.RedirectingResponse.AsActionResult(); } catch(Exception e) { ModelState.AddModelError(e.Message, "Cannot Fetch Steam Credentials. Please try again Later"); } return View(log); }