public Account GetAuthenticatedAccount() { if (HttpContext.Current.Request["Authenticator"] != null && HttpContext.Current.Request["accountID"] != null) { SSORequest ssoRequest = SSORequest.GetRequest(HttpContext.Current); string actID = ssoRequest.AccountID; if (Authentication.ValidateEACToken(ssoRequest) && !string.IsNullOrEmpty(actID) && We7Helper.IsGUID(actID)) { Security.SetAccountID(actID); return(RemoteHelper.GetAccount(actID, null)); } else { return(null); } } else if (HttpContext.Current.Request["Authenticator"] == null) { SSORequest req = new SSORequest(); req.Action = "authenticate"; req.SiteID = SiteConfigs.GetConfig().SiteID; Authentication.CreateAppToken(req); Authentication.Post(req, SiteConfigs.GetConfig().PassportAuthPage); return(null); } else { return(null); } }
public string[] Login(string name, string password) { string[] result = { "", "" }; if (HttpContext.Current.Request["Authenticator"] == null) { SSORequest req = new SSORequest(); req.Action = "signin"; req.UserName = name; req.Password = password; req.SiteID = SiteConfigs.GetConfig().SiteID; Authentication.CreateAppToken(req); Authentication.Post(req, SiteConfigs.GetConfig().PassportAuthPage); } //else if (Request["Authenticator"] != null && Request["accountID"] != null) //{ // SSORequest ssoRequest = SSORequest.GetRequest(HttpContext.Current); // string actID = ssoRequest.AccountID; // if (Authentication.ValidateEACToken(ssoRequest) && !string.IsNullOrEmpty(actID) && We7Helper.IsGUID(actID)) // { // Security.SetAccountID(actID); // result[0] = "true"; // result[1] = actID; // } // else if (Request["message"] != null) // { // result[0] = "false"; // result[1] = Request["message"]; // } //} return(result); }
public static void Post(SSORequest ssoRequest, string url) { PostService ps = new PostService(); ps.Url = url; ps.Add("Action", ssoRequest.Action); if (!string.IsNullOrEmpty(ssoRequest.SiteID)) { ps.Add("SiteID", ssoRequest.SiteID); } if (!string.IsNullOrEmpty(ssoRequest.AccountID)) { ps.Add("AccountID", ssoRequest.AccountID); } if (!string.IsNullOrEmpty(ssoRequest.UserName)) { ps.Add("UserName", ssoRequest.UserName); } if (!string.IsNullOrEmpty(ssoRequest.Password)) { ps.Add("Password", ssoRequest.Password); } ps.Add("TimeStamp", ssoRequest.TimeStamp); ps.Add("AppUrl", ssoRequest.AppUrl); ps.Add("Authenticator", ssoRequest.Authenticator); ps.Post(); }
public static void PostChains(SSORequest ssoRequest) { string leavesToUrls = string.Empty; string url = GetCurrentUrl(ssoRequest.ToUrls, ref leavesToUrls); ssoRequest.ToUrls = leavesToUrls; if (!String.IsNullOrEmpty(url)) { PostService ps = new PostService(); ps.Url = url; ps.Add("Action", ssoRequest.Action); ps.Add("ToUrls", ssoRequest.ToUrls); if (!String.IsNullOrEmpty(ssoRequest.UserName)) { ps.Add("UserName", ssoRequest.UserName); } if (!String.IsNullOrEmpty(ssoRequest.Password)) { ps.Add("Password", ssoRequest.Password); } ps.Add("AppUrl", ssoRequest.AppUrl); ps.Post(); } else { HttpContext.Current.Response.Redirect(ssoRequest.AppUrl); } }
/// <summary> /// 验证从认证中心发送过来的 Token /// </summary> /// <param name="ssoRequest"></param> /// <returns></returns> public static bool ValidateEACToken(SSORequest ssoRequest) { string Authenticator = ssoRequest.Authenticator; string OriginalAuthenticator = ssoRequest.AccountID + ssoRequest.SiteID + ssoRequest.TimeStamp + ssoRequest.AppUrl; string AuthenticatorDigest = CryptoHelper.ComputeHashString(OriginalAuthenticator); string sToEncrypt = OriginalAuthenticator + AuthenticatorDigest; byte[] bToEncrypt = CryptoHelper.ConvertStringToByteArray(sToEncrypt); string EncryCurrentAuthenticator = string.Empty; CryptoService cs = GetCryptoService(); byte[] encrypted; if (cs.Encrypt(bToEncrypt, out encrypted)) { EncryCurrentAuthenticator = CryptoHelper.ToBase64String(encrypted); return(Authenticator == EncryCurrentAuthenticator); } else { return(false); } }
public string SignOut() { string result = ""; if (HttpContext.Current.Request["Authenticator"] == null) { Security.SignOut(); SSORequest req = new SSORequest(); req.Action = "signout"; req.SiteID = SiteConfigs.GetConfig().SiteID; Authentication.CreateAppToken(req); Authentication.Post(req, SiteConfigs.GetConfig().PassportAuthPage); } return(result); }
public string[] Login(string username, string password) { string[] results = { "", "" }; if (HttpContext.Current.Request["Authenticator"] != null) { SSORequest ssoRequest = new SSORequest(); ssoRequest.Action = "signin"; ssoRequest.UserName = username; ssoRequest.Password = password; ssoRequest.SiteID = SiteConfigs.GetConfig().SiteID; Authentication.CreateAppToken(ssoRequest); Authentication.Post(ssoRequest, SiteConfigs.GetConfig().PassportAuthPage); } return(results); }
/// <summary> /// 获取当前页面上的SSORequest对象 /// </summary> /// <param name="CurrentPage"></param> /// <returns></returns> public static SSORequest GetRequest(HttpContext CurrentPage) { SSORequest request = new SSORequest(); request.IPAddress = CurrentPage.Request.UserHostAddress; request.Action = CurrentPage.Request["Action"]; request.SiteID = CurrentPage.Request["SiteID"]; request.AccountID = CurrentPage.Request["AccountID"]; request.UserName = CurrentPage.Request["UserName"]; request.Password = CurrentPage.Request["Password"]; request.AppUrl = CurrentPage.Request["AppUrl"]; request.Authenticator = CurrentPage.Request["Authenticator"]; request.TimeStamp = CurrentPage.Request["TimeStamp"]; request.ToUrls = CurrentPage.Request["ToUrls"]; request.FromUrls = CurrentPage.Request["FromUrls"]; return(request); }