public override bool ValidateUser(string username, string password)
        {
            bool ret = true;
            try
            {

                Uri userUri = Utility.NormalizeIdentityUrl(username);
                HttpContext Context = HttpContext.Current;
                HttpSessionState Session = Context.Session;
                HttpRequest Request = Context.Request;
                HttpResponse Response = Context.Response;
                Janrain.OpenId.Consumer.Consumer consumer;

                if (consumerSession == null)
                {
                    consumerSession = new Janrain.OpenId.Session.SimpleSessionState();
                }
                consumer = new Janrain.OpenId.Consumer.Consumer(consumerSession,
                                                                Janrain.OpenId.Store.MemoryStore.GetInstance());
                if (username != null)
                {
                    try
                    {
                        AuthRequest request = consumer.Begin(userUri);
                        // Build the trust root
                        UriBuilder builder = new UriBuilder(Request.Url.AbsoluteUri);
                        builder.Query = null;
                        builder.Password = null;
                        builder.UserName = null;
                        builder.Fragment = null;
                        builder.Path = Request.ApplicationPath;
                        // The following approach does not append port 80 in the
                        // no port case.
                        string trustRoot = (new Uri(builder.ToString())).ToString();
                        // Build the return_to URL
                        builder = new UriBuilder(Request.Url.AbsoluteUri);
                        NameValueCollection col = new NameValueCollection();
                        col["ReturnUrl"] = Request.QueryString["ReturnUrl"];
                        builder.Query = Janrain.OpenId.UriUtil.CreateQueryString(col);
                        Uri returnTo = new Uri(builder.ToString());
                        Uri redirectUrl = request.CreateRedirect(trustRoot, returnTo, AuthRequest.Mode.SETUP);
                        // The following illustrates how to use SREG.
                        String uriString = redirectUrl.AbsoluteUri + "&openid.sreg.optional=" + _optionalInformation;
                        // Get the current page
                        _loginURL = Context.Request.Url.AbsoluteUri;
                        // Redirect the user to the OpenID provider Page
                        Response.Redirect(uriString, true);
                    }
                    catch (System.Threading.ThreadAbortException)
                    {
                        // Consume. This is normal during redirect.
                    }
                }
                else
                {
                    ret = false;
                }
            }
            catch
            {
                return false;
            }
            return ret;
        }
예제 #2
0
        public bool ValidateOpenIDUser()
        {
            bool             ret     = true;
            HttpContext      Context = HttpContext.Current;
            HttpSessionState Session = Context.Session;
            HttpRequest      Request = Context.Request;

            Janrain.OpenId.Consumer.Consumer consumer;

            try
            {
                if (consumerSession == null)
                {
                    consumerSession = new Janrain.OpenId.Session.SimpleSessionState();
                }
                consumer = new Janrain.OpenId.Consumer.Consumer(consumerSession,
                                                                Janrain.OpenId.Store.MemoryStore.GetInstance());
            }
            catch
            {
                return(false);
            }

            if (Request.QueryString["openid.mode"] != null && Request.QueryString["openid.mode"] != "Cancel")
            {
                try
                {
                    _country    = (Request.QueryString["openid.sreg.country"] ?? "");
                    _dayOfBirth = (Request.QueryString["openid.sreg.dob"] ?? "");
                    _email      = (Request.QueryString["openid.sreg.email"] ?? "");
                    _fullname   = (Request.QueryString["openid.sreg.fullname"] ?? "");
                    _gender     = (Request.QueryString["openid.sreg.gender"] ?? "");
                    _language   = (Request.QueryString["openid.sreg.language"] ?? "");
                    _nickname   = (Request.QueryString["openid.sreg.nickname"] ?? "");
                    _postcode   = (Request.QueryString["openid.sreg.postcode"] ?? "");
                    _timezone   = (Request.QueryString["openid.sreg.timezone"] ?? "");

                    ConsumerResponse resp         = consumer.Complete(Request.QueryString);
                    string           userIdentity = Utility.IdentityUrlToDisplayString(resp.IdentityUrl);
                    MembershipUser   user         = GetUserByOpenId(userIdentity, true);
                    ret = (user != null);
                    if (ret)
                    {
                        FormsAuthentication.RedirectFromLoginPage(user.UserName, false);
                    }
                    else
                    {
                        OpenIdNotLinkedException exception = new OpenIdNotLinkedException(userIdentity);
                        throw exception;
                    }
                }
                catch (FailureException fexc)
                {
                    if (WriteExceptionsToEventLog)
                    {
                        Utility.WriteToEventLog(fexc, "ValidateOpenIDUser");
                    }
                    ret = false;
                }
                catch (OpenIdNotLinkedException nlEx)
                {
                    throw nlEx;
                }
                catch (Exception fe)
                {
                    if (WriteExceptionsToEventLog)
                    {
                        Utility.WriteToEventLog(fe, "ValidateOpenIDUser");
                    }
                    throw new OpenIdMembershipProviderException(fe.Message, fe.Source, fe.StackTrace);
                }
            }
            else
            {
                ret = false;
            }
            return(ret);
        }
        public bool ValidateOpenIDUser()
        {
            bool ret = true;
            HttpContext Context = HttpContext.Current;
            HttpSessionState Session = Context.Session;
            HttpRequest Request = Context.Request;
            Janrain.OpenId.Consumer.Consumer consumer;

            try
            {
                if (consumerSession == null)
                {
                    consumerSession = new Janrain.OpenId.Session.SimpleSessionState();
                }
                consumer = new Janrain.OpenId.Consumer.Consumer(consumerSession,
                                                                Janrain.OpenId.Store.MemoryStore.GetInstance());
            }
            catch
            {
                return false;
            }

            if (Request.QueryString["openid.mode"] != null && Request.QueryString["openid.mode"] != "Cancel")
            {
                try
                {
                    _country = (Request.QueryString["openid.sreg.country"] ?? "");
                    _dayOfBirth = (Request.QueryString["openid.sreg.dob"] ?? "");
                    _email = (Request.QueryString["openid.sreg.email"] ?? "");
                    _fullname = (Request.QueryString["openid.sreg.fullname"] ?? "");
                    _gender = (Request.QueryString["openid.sreg.gender"] ?? "");
                    _language = (Request.QueryString["openid.sreg.language"] ?? "");
                    _nickname = (Request.QueryString["openid.sreg.nickname"] ?? "");
                    _postcode = (Request.QueryString["openid.sreg.postcode"] ?? "");
                    _timezone = (Request.QueryString["openid.sreg.timezone"] ?? "");

                    ConsumerResponse resp = consumer.Complete(Request.QueryString);
                    string userIdentity = Utility.IdentityUrlToDisplayString(resp.IdentityUrl);
                    MembershipUser user = GetUserByOpenId(userIdentity, true);
                    ret = (user != null);
                    if (ret)
                    {
                        FormsAuthentication.RedirectFromLoginPage(user.UserName, false);
                    }
                    else
                    {
                        OpenIdNotLinkedException exception = new OpenIdNotLinkedException(userIdentity);
                        throw exception;
                    }
                }
                catch (FailureException fexc)
                {
                    if (WriteExceptionsToEventLog)
                    {
                        Utility.WriteToEventLog(fexc, "ValidateOpenIDUser");
                    }
                    ret = false;
                }
                catch (OpenIdNotLinkedException nlEx)
                {
                    throw nlEx;
                }
                catch (Exception fe)
                {
                    if (WriteExceptionsToEventLog)
                    {
                        Utility.WriteToEventLog(fe, "ValidateOpenIDUser");
                    }
                    throw new OpenIdMembershipProviderException(fe.Message, fe.Source, fe.StackTrace);
                }
            }
            else
            {
                ret = false;
            }
            return ret;
        }
예제 #4
0
        public override bool ValidateUser(string username, string password)
        {
            bool ret = true;

            try
            {
                Uri              userUri  = Utility.NormalizeIdentityUrl(username);
                HttpContext      Context  = HttpContext.Current;
                HttpSessionState Session  = Context.Session;
                HttpRequest      Request  = Context.Request;
                HttpResponse     Response = Context.Response;
                Janrain.OpenId.Consumer.Consumer consumer;

                if (consumerSession == null)
                {
                    consumerSession = new Janrain.OpenId.Session.SimpleSessionState();
                }
                consumer = new Janrain.OpenId.Consumer.Consumer(consumerSession,
                                                                Janrain.OpenId.Store.MemoryStore.GetInstance());
                if (username != null)
                {
                    try
                    {
                        AuthRequest request = consumer.Begin(userUri);
                        // Build the trust root
                        UriBuilder builder = new UriBuilder(Request.Url.AbsoluteUri);
                        builder.Query    = null;
                        builder.Password = null;
                        builder.UserName = null;
                        builder.Fragment = null;
                        builder.Path     = Request.ApplicationPath;
                        // The following approach does not append port 80 in the
                        // no port case.
                        string trustRoot = (new Uri(builder.ToString())).ToString();
                        // Build the return_to URL
                        builder = new UriBuilder(Request.Url.AbsoluteUri);
                        NameValueCollection col = new NameValueCollection();
                        col["ReturnUrl"] = Request.QueryString["ReturnUrl"];
                        builder.Query    = Janrain.OpenId.UriUtil.CreateQueryString(col);
                        Uri returnTo    = new Uri(builder.ToString());
                        Uri redirectUrl = request.CreateRedirect(trustRoot, returnTo, AuthRequest.Mode.SETUP);
                        // The following illustrates how to use SREG.
                        String uriString = redirectUrl.AbsoluteUri + "&openid.sreg.optional=" + _optionalInformation;
                        // Get the current page
                        _loginURL = Context.Request.Url.AbsoluteUri;
                        // Redirect the user to the OpenID provider Page
                        Response.Redirect(uriString, true);
                    }
                    catch (System.Threading.ThreadAbortException)
                    {
                        // Consume. This is normal during redirect.
                    }
                }
                else
                {
                    ret = false;
                }
            }
            catch
            {
                return(false);
            }
            return(ret);
        }