public virtual void ProcessRequest(HttpContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            var state = ReadStateQueryParameter(context);

            if (!(GetValue(context, state, AuthServiceProvider.ProviderParameter) is string providerName))
            {
                return;
            }

            AuthenticationElement authenticationElement = GetAuthenticationElement();
            AuthServiceProvider   provider = GetServiceProvider(providerName);

            if (provider == null)
            {
                return;
            }

            AuthLoginOptions loginOptions = ConvertUtilities.ChangeType(GetValue(context, state, AuthServiceProvider.OptionsParameter), AuthLoginOptions.None);

            int      attempt  = 0;
            UserData userData = null;

            while (attempt < authenticationElement.MaximumRetryCount)
            {
                try
                {
                    userData = provider.GetUserData(context);
                    break;
                }
                catch (Exception ex)
                {
                    if (!OnGetUserDataError(context, ex, attempt))
                    {
                        break;
                    }

                    attempt++;
                    if (authenticationElement.RetryInterval > 0)
                    {
                        Thread.Sleep(authenticationElement.RetryInterval);
                    }
                }
            }

            if (userData == null)
            {
                Authenticate(context, provider, loginOptions);
            }
            else
            {
                Authenticate(context, provider, loginOptions, userData);
            }
        }
        public virtual void Login(AuthLoginOptions options)
        {
            LoginOptions = options;
            switch (Protocol)
            {
            case AuthProtocol.OAuth10a:
                LoginOAuth10a();
                break;

            case AuthProtocol.OpenIdOAuth:
                LoginOpenIdOAuth();
                break;

            case AuthProtocol.OAuth20:
                LoginOAuth20();
                break;

            default:
                throw new NotSupportedException();
            }
        }
 protected virtual bool Authenticate(HttpContext context, AuthServiceProvider provider, AuthLoginOptions options, UserData userData)
 {
     return(true);
 }
        protected override bool Authenticate(HttpContext context, AuthServiceProvider provider, AuthLoginOptions options, UserData userData)
        {
            string userName = userData.Email ?? userData.Name;

            if (string.IsNullOrEmpty(userName))
            {
                return(false);
            }

            // create the user if he doesn't exist
            MembershipUser user = new MembershipUser("AspNetSqlMembershipProvider", userName, userName, userName, "AA", "AA", true, false, DateTime.Now, DateTime.Now, DateTime.Now, DateTime.Now, DateTime.Now);

            //MembershipUser user = Membership.GetUser(email);
            if (user == null)
            {
                string password = Membership.GeneratePassword(8, 0);
                user = Membership.CreateUser(userData.Email, password, userData.Email);
            }

            if ((options & AuthLoginOptions.Device) == AuthLoginOptions.Device)
            {
                HttpCookie authCookie = GetAuthCookie(userName, true, false);
                context.Response.Cookies.Add(authCookie);

                HttpCookie emailCookie = new HttpCookie(".EMAIL", userName)
                {
                    HttpOnly = false
                };
                context.Response.Cookies.Add(emailCookie);
            }
            else
            {
                // do Forms login
                HttpCookie authCookie = GetAuthCookie(userName, true, true);
                context.Response.Cookies.Add(authCookie);

                RedirectSuccess(context);
            }

            return(true);
        }