protected void Page_Load() { // Process the result from an auth provider in the request ProviderName = IdentityConfig.GetProviderNameFromRequest(Request); if (String.IsNullOrEmpty(ProviderName)) { Response.Redirect("~/Account/Login"); } if (!IsPostBack) { RegisterAsyncTask(new System.Web.UI.PageAsyncTask(RegisterExternalLoginAsync)); } }
protected void Page_Load() { // Process the result from an auth provider in the request ProviderName = IdentityConfig.GetProviderNameFromRequest(Request); if (String.IsNullOrEmpty(ProviderName)) { Response.Redirect("~/Account/Login"); } if (!IsPostBack) { var manager = new IdentityAuthenticationManagerSync(); ClaimsIdentity id = manager.GetExternalIdentity(new HttpContextWrapper(Context)); if (!manager.VerifyExternalIdentity(id, ProviderName)) { ModelState.AddModelError(String.Empty, "There was an error processing this request."); return; } if (manager.SignInExternalIdentity(new HttpContextWrapper(Context), id, ProviderName)) { IdentityConfig.RedirectToReturnUrl(Request.QueryString["ReturnUrl"], Response); } else if (User.Identity.IsAuthenticated) { if (manager.LinkExternalIdentity(id, User.Identity.GetUserId(), ProviderName)) { IdentityConfig.RedirectToReturnUrl(Request.QueryString["ReturnUrl"], Response); } else { ModelState.AddModelError(String.Empty, "There was an error processing this request."); return; } } else { userName.Text = id.Name; } } }