Beispiel #1
0
        protected void GetDefaultAccountByUrl(string url, out WinDemo.BaseConst.Realm rlm, out string userName, out string pwd,
                                              out string consumerKey, out string consumerSecret)
        {
            rlm            = BaseConst.Realm.People;
            userName       = BaseConst.PortalUserName;
            consumerKey    = BaseConst.ConsumerKey1stParty;
            consumerSecret = BaseConst.ConsumerSecret1stParty;

            pwd = BaseConst.PortalUserPassword;

            if (url.Contains(WinDemo.BaseConst.Realm.People.ToString()))
            {
                userName = BaseConst.PortalUserName;
                pwd      = BaseConst.PortalUserPassword;
                rlm      = BaseConst.Realm.People;
            }
            else if (url.Contains(WinDemo.BaseConst.Realm.Groups.ToString()))
            {
                //TODO  userName

                rlm = BaseConst.Realm.Groups;
            }
            else if (url.Contains(WinDemo.BaseConst.Realm.Giving.ToString()))
            {
                //TODO userName

                rlm = WinDemo.BaseConst.Realm.Giving;
            }
            else if (url.Contains(WinDemo.BaseConst.Realm.Events.ToString()))
            {
                //

                rlm = BaseConst.Realm.Events;
            }
        }
Beispiel #2
0
        private void SendRequest()
        {
            WinDemo.BaseConst.Realm rlm = BaseConst.Realm.People;
            string userName             = "";
            string pwd            = "";
            string consumerKey    = "";
            string consumerSecret = "";

            GetDefaultAccountByUrl(txtApiUrl.Text.Trim(), out rlm, out userName, out pwd, out consumerKey, out consumerSecret);

            txtUserName.Text       = userName;
            txtPwd.Text            = pwd;
            txtConsumerKey.Text    = consumerKey;
            txtConsumerSecret.Text = consumerSecret;

            try
            {
                GetAccessTokenForPortalUser(txtUserName.Text.Trim(), txtPwd.Text.Trim(), rlm, consumerKey, consumerSecret);

                using (WebResponse responseObj = GetWebResponse(rlm, OAuthBase.HMACSHA1SignatureType, "application/xml", txtHttpMethod.Text.Trim(), txtApiUrl.Text.Trim(), null,
                                                                txtConsumerKey.Text.Trim(), txtConsumerSecret.Text.Trim()))
                {
                    using (StreamReader sr = new StreamReader(responseObj.GetResponseStream()))
                    {
                        txtResponseContent.AppendText("Success! The response content is : \n");
                        txtResponseContent.AppendText(sr.ReadToEnd());
                    }
                }
            }
            catch (WebException we)
            {
                txtResponseContent.AppendText(we.GetType() + "\n");
                txtResponseContent.AppendText(we.Message + "\n");
                txtResponseContent.AppendText("-------------------------------------");

                txtResponseContent.AppendText(we.StackTrace);
            }
            catch (System.Net.ProtocolViolationException pve)
            {
                txtResponseContent.AppendText(pve.GetType() + "\n");
                txtResponseContent.AppendText(pve.Message + "\n");
                txtResponseContent.AppendText("-------------------------------------");

                txtResponseContent.AppendText(pve.StackTrace);
            }
        }