public void Cb(string type) { string target = Request.QueryString["target"]; if (string.IsNullOrEmpty(target)) { target = GetUrl("/"); } OAuth2Provider provider = GetProvider(type); if (provider != null) { OAuth2TokenAccess token = provider.Access() as OAuth2TokenAccess; M.OAuth2Member user = provider.GetUserInfo(token); if (!string.IsNullOrEmpty(user.UserId)) { M.Member member; M.LoginStatus status = M.OAuth2Member.Login(DataSource, type.ToLower(), user.UserId, ClientIp, out member); if (status == M.LoginStatus.Success) { PassportAuthentication.SetAuthCookie(true, false, member); OnLogined(member.Id); Refresh(target); } else { if (status == M.LoginStatus.NeedBind) { this["Oauth2Type"] = user.Type; this["Oauth2UserId"] = user.UserId; this["Target"] = target; this["Sms"] = SMSCaptchaSection.GetSection(); Render("oauth2.html"); } else { Redirect(GetUrl("/login")); } } } else { Redirect(GetUrl("/login")); } } else { Redirect(GetUrl("/login")); } }
public void Bind() { try { //string target = Request.Form["Target"]; //if (string.IsNullOrEmpty(target)) // target = GetUrl("/"); string type = Request.Form["Oauth2Type"]; string userId = Request.Form["Oauth2UserId"]; M.RegisterType rt = (M.RegisterType) int.Parse(Request.Form["RegisterType"]); M.Member member = DbTable.Load <M.Member>(Request.Form); if (rt == M.RegisterType.Mobile) { if (!V.MobileHash.Equals(DataSource, member.Mobile, V.MobileHash.Register, Request.Form["Captcha"])) { SetResult((int)M.LoginStatus.CaptchaError); return; } member.VerMob = true; } string password = member.Password; member.ParentId = Utility.GetReference(this, DataSource); member.Approved = true; member.CreationDate = DateTime.Now; DataStatus status = M.OAuth2Member.Register(DataSource, type, userId, member, rt); if (status == DataStatus.Success) { M.LoginStatus state = M.OAuth2Member.Login(DataSource, type, userId, ClientIp, out member); if (state == M.LoginStatus.Success) { PassportAuthentication.SetAuthCookie(true, false, member); OnLogined(member.Id); SetResult(true); } else { SetResult((int)state); } } else { SetResult((int)status); } } catch (Exception) { SetResult(false); } }
public static bool CheckCaptcha(string name, string code) { HttpCookie cookie = HttpContext.Current.Request.Cookies[string.Concat(CAPTCHA_SECTION.CookiePrefix, name)]; if (cookie != null) { byte[] bytes = PassportAuthentication.DecodeCookie(cookie.Value); DateTime time = new DateTime(BitConverter.ToInt64(bytes, 0)); if (time.AddMinutes(CAPTCHA_SECTION.Expiration) > DateTime.Now) { return(string.Equals(code, Encoding.UTF8.GetString(bytes, 8, bytes.Length - 8), StringComparison.OrdinalIgnoreCase)); } } return(false); }
public void Custom(string name, int width = Utility.CaptchaDefaultWidth, int height = Utility.CaptchaDefaultHeight, int count = Utility.CaptchaDefaultCount) { Response.Cache.SetCacheability(HttpCacheability.NoCache); string code = RandCode(); List <byte> bytes = new List <byte>(); bytes.AddRange(BitConverter.GetBytes(DateTime.Now.Ticks)); bytes.AddRange(Encoding.UTF8.GetBytes(code)); string cookieName = string.Concat(CAPTCHA_SECTION.CookiePrefix, (name ?? string.Empty)); Response.Cookies[cookieName].Value = PassportAuthentication.EncodeCookie(bytes.ToArray()); if (!string.IsNullOrEmpty(CAPTCHA_SECTION.CookieDomain)) { Response.Cookies[cookieName].Domain = CAPTCHA_SECTION.CookieDomain; } CreateImage(Context, code, width, height); }
public void Index() { string target = Request.QueryString["target"]; if (string.IsNullOrEmpty(target)) { if (Request.UrlReferrer != null) { target = Request.UrlReferrer.ToString(); } } if (string.IsNullOrEmpty(target)) { target = GetUrl("ucenter"); } OnLogouted(User.Identity.Id); PassportAuthentication.SignOut(); Refresh(target); }
public UsingPassportAuthentication() { // <Snippet1> // Get the configuration. // Get the Web application configuration. System.Configuration.Configuration configuration = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/aspnetTest"); // Get the section. System.Web.Configuration.AuthenticationSection authenticationSection = (System.Web.Configuration.AuthenticationSection)configuration.GetSection("system.web/authentication"); // Get the authentication passport element. PassportAuthentication passport = authenticationSection.Passport; // </Snippet1> // <Snippet2> // Create a new passport object. PassportAuthentication newPassport = new PassportAuthentication(); // </Snippet2> // <Snippet3> // Get the passport redirect URL string redirectUrl = passport.RedirectUrl; // Set passport redirect Url. passport.RedirectUrl = "passportLogin.aspx"; if (!authenticationSection.SectionInformation.IsLocked) { configuration.Save(); } // </Snippet3> }
protected virtual bool CheckRight(Arguments args = null) { //string origin = Request.Headers["Origin"]; //if (!string.IsNullOrEmpty(origin)) //{ // string token = Request.QueryString["token"]; // if (!string.IsNullOrEmpty(token)) // { // //Response.Headers.Add("Access-Control-Allow-Origin", origin); // //Response.Headers.Add("Access-Control-Allow-Methods", "GET, POST"); // PassportAuthentication.SetAuthToken(token, Context); // } //} string token = Request.QueryString["token"]; if (!string.IsNullOrEmpty(token)) { PassportAuthentication.SetAuthToken(token, Context); } if (User != null && User.Identity != null && User.Identity.IsAuthenticated) { return(true); } if (args != null && args.Count > 0) { token = string.Join("/", args.ToArray()); PassportAuthentication.SetAuthToken(token, Context); if (User != null && User.Identity != null && User.Identity.IsAuthenticated) { return(true); } } Unauthorized(); return(false); }
public static void Main() { // <Snippet1> // Get the Web application configuration. System.Configuration.Configuration configuration = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration( "/aspnetTest"); // Get the section. AuthenticationSection authenticationSection = (AuthenticationSection)configuration.GetSection( "system.web/authentication"); // </Snippet1> // <Snippet2> AuthenticationSection newauthenticationSection = new AuthenticationSection(); // </Snippet2> // <Snippet3> // Get the current Passport property. PassportAuthentication currentPassport = authenticationSection.Passport; // Get the Passport redirect URL. string passRedirectUrl = currentPassport.RedirectUrl; // </Snippet3> // <Snippet4> // Get the current Mode property. AuthenticationMode currentMode = authenticationSection.Mode; // Set the Mode property to Windows. authenticationSection.Mode = AuthenticationMode.Windows; // </Snippet4> // <Snippet5> // Get the current Forms property. FormsAuthenticationConfiguration currentForms = authenticationSection.Forms; // Get the Forms attributes. string name = currentForms.Name; string login = currentForms.LoginUrl; string path = currentForms.Path; HttpCookieMode cookieLess = currentForms.Cookieless; bool requireSSL = currentForms.RequireSSL; bool slidingExpiration = currentForms.SlidingExpiration; bool enableXappRedirect = currentForms.EnableCrossAppRedirects; TimeSpan timeout = currentForms.Timeout; FormsProtectionEnum protection = currentForms.Protection; string defaultUrl = currentForms.DefaultUrl; string domain = currentForms.Domain; // </Snippet5> }