/// <summary> /// 回调页面 /// </summary> public ActionResult LoginCallback(LoginModel model, string returnUrl) { QOpenClient qzone = (QOpenClient)this.Session["QzoneOauth"]; var verifier = Request.Params["code"]; var state = Request.Params["state"]; if (Request.Params["code"] != null) { if (qzone == null) { var storeScope = this.GetActiveStoreScopeConfiguration(_storeService, _workContext); var qqExternalAuthSettings = _settingService.LoadSetting <QQExternalAuthSettings>(storeScope); qzone = new QOpenClient(verifier, state, new QQConnectConfig(qqExternalAuthSettings.AppKey, qqExternalAuthSettings.AppSecret, qqExternalAuthSettings.CallBackURI, qqExternalAuthSettings.AuthorizeURL)); if (qzone != null) { this.Session["QzoneOauth"] = qzone; } } else { qzone = (QOpenClient)this.Session["QzoneOauth"]; } string requestState = Session["requeststate"].ToString(); if (state == requestState) { if (qzone.OAuthToken != null) { if (string.IsNullOrEmpty(qzone.OAuthToken.OpenId)) { throw new Exception("Authentication result does not contain openid"); } if (string.IsNullOrEmpty(qzone.OAuthToken.AccessToken)) { throw new Exception("Authentication result does not contain accesstoken data"); } var parameters = new OAuthAuthenticationParameters(Provider.SystemName) { ExternalIdentifier = qzone.OAuthToken.OpenId, OAuthToken = qzone.OAuthToken.AccessToken, OAuthAccessToken = qzone.OAuthToken.OpenId, }; UserClaims claims = new UserClaims(); claims.Contact = new ContactClaims(); parameters.AddClaim(claims); Session["QQAuthorizeParameters"] = parameters; var result = _authorizer.Authorize(parameters); switch (result.Status) { case OpenAuthenticationStatus.Error: { if (!result.Success) { foreach (var error in result.Errors) { ExternalAuthorizerHelper.AddErrorsToDisplay(error); } } return(RedirectToRoute("ThirdAccountRegister", new { styleId = 1 })); } case OpenAuthenticationStatus.AssociateOnLogon: { return(new RedirectResult(Url.LogOn(returnUrl))); } case OpenAuthenticationStatus.AutoRegisteredEmailValidation: { //result return(RedirectToRoute("RegisterResult", new { resultId = (int)UserRegistrationType.EmailValidation })); } case OpenAuthenticationStatus.AutoRegisteredAdminApproval: { return(RedirectToRoute("RegisterResult", new { resultId = (int)UserRegistrationType.AdminApproval })); } case OpenAuthenticationStatus.AutoRegisteredStandard: { return(RedirectToRoute("RegisterResult", new { resultId = (int)UserRegistrationType.Standard })); } default: break; } } return(Redirect(Url.Action("Index", "Home"))); } } return(View()); }
/// <summary> /// 回调页面 /// </summary> public ActionResult LoginCallback(LoginModel model, string returnUrl) { Client sinaWebzone = this.Session["SinaWebOauth"] as Client; var verifier = Request.Params["code"]; if (verifier != null) { if (sinaWebzone == null) { var storeScope = this.GetActiveStoreScopeConfiguration(_storeService, _workContext); var sinaWebExternalAuthSettings = _settingService.LoadSetting <SinaWebExternalAuthSettings>(storeScope); sinaWebzone = new Client(new OAuth(sinaWebExternalAuthSettings.AppKey, sinaWebExternalAuthSettings.AppSecret, sinaWebExternalAuthSettings.CallBackURI)); sinaWebzone.OAuth.GetAccessTokenByAuthorizationCode(verifier); if (sinaWebzone != null) { this.Session["SinaWebOauth"] = sinaWebzone; } } else { sinaWebzone = (Client)this.Session["SinaWebOauth"]; } if (sinaWebzone.OAuth != null) { if (string.IsNullOrEmpty(sinaWebzone.API.Entity.Account.GetUID())) { throw new Exception("Authentication result does not contain openid"); } if (string.IsNullOrEmpty(sinaWebzone.OAuth.AccessToken)) { throw new Exception("Authentication result does not contain accesstoken data"); } var parameters = new OAuthAuthenticationParameters(Provider.SystemName) { ExternalIdentifier = sinaWebzone.API.Entity.Account.GetUID(), OAuthToken = sinaWebzone.OAuth.AccessToken, OAuthAccessToken = sinaWebzone.API.Entity.Account.GetUID(), }; UserClaims claims = new UserClaims(); claims.Contact = new ContactClaims(); parameters.AddClaim(claims); Session["SinaWebAuthorizeParameters"] = parameters; var result = _authorizer.Authorize(parameters); switch (result.Status) { case OpenAuthenticationStatus.Error: { if (!result.Success) { foreach (var error in result.Errors) { ExternalAuthorizerHelper.AddErrorsToDisplay(error); } } return(RedirectToRoute("ThirdAccountRegister", new { styleId = 2 })); } case OpenAuthenticationStatus.AssociateOnLogon: { return(new RedirectResult(Url.LogOn(returnUrl))); } case OpenAuthenticationStatus.AutoRegisteredEmailValidation: { //result return(RedirectToRoute("RegisterResult", new { resultId = (int)UserRegistrationType.EmailValidation })); } case OpenAuthenticationStatus.AutoRegisteredAdminApproval: { return(RedirectToRoute("RegisterResult", new { resultId = (int)UserRegistrationType.AdminApproval })); } case OpenAuthenticationStatus.AutoRegisteredStandard: { return(RedirectToRoute("RegisterResult", new { resultId = (int)UserRegistrationType.Standard })); } default: break; } } return(Redirect(Url.Action("Index", "Home"))); } return(View()); }