Exemplo n.º 1
0
        /// <summary>
        /// Gets the user details.
        /// </summary>
        public override UserInfo GetUserInfo()
        {
            // query parameters
            var parameters = new NameValueCollection
            {
                { "access_token", this.AccessToken["access_token"].ToString() }
            };

            // execute the request
            var result = OAuthUtility.ExecuteRequest
                         (
                "GET",
                "https://api.amazon.com/user/profile",
                parameters
                         );

            // field mapping
            var map = new ApiDataMapping();

            map.Add("user_id", "UserId");
            map.Add("name", "DisplayName");
            map.Add("email", "Email");

            // parse the server response and returns user info
            return(new UserInfo(result.Result as Dictionary <string, object>, map));
        }
Exemplo n.º 2
0
        public ActionResult Google(string method)
        {
            try
            {
                if (Session["Google:AccessToken"] == null)
                {
                    throw new Exception(Test.Resources.Strings.SessionIsDead);
                }

                var parameters = new NameValueCollection
                {
                    { "access_token", Session["Google:AccessToken"].ToString() }
                };

                string url = String.Format("https://www.google.com/m8/feeds/contacts/{0}/full", HttpUtility.UrlEncode(Session["Google:Email"].ToString()));

                // execute the request
                var result = OAuthUtility.ExecuteRequest("GET", url, parameters);

                return(Content(Regex.Unescape(result.ToString()), "text/plain"));
            }
            catch (Exception ex)
            {
                return(Content(ex.ToString(), "text/plain"));
            }
        }
Exemplo n.º 3
0
        public void ExecuteRequestTest()
        {
            var parameters = new HttpParameterCollection
            {
                { "content", "hello world!" },
                { "contentType", "text/plain" }
            };

            var result = OAuthUtility.Get("http://api.foxtools.ru/v2/Http", parameters);

            Assert.True(result.Contains("hello world!"));

            parameters = new HttpParameterCollection
            {
                { Convert.FromBase64String("iVBORw0KGgoAAAANSUhEUgAAAFUAAABVCAYAAAA49ahaAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsIAAA7CARUoSoAAAAR/SURBVHhe7ZDRbiMxDAPv/3+6px62gDomzGVsb+4hA0wNiJSS5k/x9aSO3X3mp70+U4endOzuMz/t9Zk6PKVjd5/5aa/P1OEpHbv7zE97feY43Im7n+ZO4vJV1P16x+FO3P00dxKXr6Lu1zsOd+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O4nJHun+6f4e6Mz/K3Elc7kj3T/fvUHfmR5k7icsd6f7p/h3qzvwocydxuSPdP92/Q92ZH2XuJC53uP2nc+e1Mw47zJ3E5Q63/3TuvHbGYYe5k7jc4fafzp3XzjjsMHcSlzvc/tO589oZhztJ77NPiep0HWpn5h2qly8lpPfZp0R1ug61M/MO1cuXEtL77FOiOl2H2pl5h+rlSwnpffYpUZ2uQ+3MvEP19PIpSZrvlqzm39T8d+m0JM13S1bzb2r+u3Rakua7Jav5NzX/XTotSfPdktX8Gz39sMDX11/4Q2CGtGAk5wAAAABJRU5ErkJggg==") },
                { "test", 123 },
                { new HttpFormParameter("x", "y") },
                { new HttpFormParameter("a", "bc") },
                { "contentType", "text/plain" }
            };

            result = OAuthUtility.Post("http://api.foxtools.ru/v2/Http", parameters);

            Assert.True(result.ToString().IndexOf("PNG") != -1);

            parameters = new HttpParameterCollection
            {
                { new HttpFile("file1", "test.png", "image/png", Convert.FromBase64String("iVBORw0KGgoAAAANSUhEUgAAAEAAAAA/CAYAAABQHc7KAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAIGNIUk0AAHolAACAgwAA+f8AAIDoAABSCAABFVgAADqXAAAXb9daH5AAACLOSURBVHja5Jp3VNTXtsd/gBRFEJA2wNBhYBgcYGboQxuGNggIIlUEISgan8ZrucbEFpNAosaSGEuaqBRJ0dhNTIiioMbevVFjiSWWaK6x6+f98/glXPG1de99d6131vouBmbWcPbn7L3PPvv8BED4/ywBEAYPHvxcDRkyRKiurhYmTJggvPbaa8Ls2bOFRYsWCU1NTcKOHTuE/fv3C+fOnRNu374tnDt3Tti/f7/Q2toqtLS0CJ988okwd+5cy9deey1s4sSJhTU1Na+WlZUtKSgo+DorK+u0Xq+/rtVqL2k0mn3BwcFNfn5+s/z8/EZ4eHjobWxs3GxsbIx69+4tmJqaCqampoKRkZHwvGFsbCz07t1bMDY2Fn+3s7MTnJ2dBScnp271DwGwb98+obW11e2zzz4rr6+vb1iwYMHp2bNnP5w9ezbz589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3ZbW9v23bt3s2bNGl555RUyMjLQarUkJiaiVCpFACqVimHDhjF79my0Wi2jRo3i7bffRqvVikZHRUURGRlJZGQkUVFRJCUlkZGRQWZmJmlpadeSk5PrIiIi3OLi4gSdTiekpKT8nwLo7CX0+Oqrr/Tt7e0NR48evXno0CHWr1/PO++8I9b3SUlJREdHEx4ejlqtFlf6j6vbaWxubi7FxcWUl5dTXl7+pLi4eH9WVta4jIwMV71eL0RGRgparfZfB8BXX30lbNy4Ufj666+F9vZ2t7a2tvJTp041nD9//vTly5cfnjp1itbWVpqbm1m4cCG1tbVMmTKFP//5z4wfP56JEycyadIkXn75ZSZPnvx0woQJv4wdO3Z7dXX1jNLS0pjCwkLTzMxMISMjQ/iXBrB161Zh586dwubNm4WDBw8KBw4csDx16lTY+fPnC3/44YdXjx07tmTPnj1ff/vtt2fWrl17vbGx8fLSpUv3zZ8/v+mtt96aNXPmzBGvvPKKfty4cdLRo0cbDR06VCgqKhKKioqEfxiA/8/69wEAGjgk0I9Qd/wAAAAASUVORK5CYII=")) },
                { "dd", 20 },
                { "id", 13 },
                { new HttpFormParameter("key", "e91268b7-1162-4044-9236-7191c8c3b5d2") },
                { "contentType", "text/plain" }
            };

            result = OAuthUtility.Post("http://api.foxtools.ru/v2/Http", parameters);

            Assert.True(result.ToString().Contains("test.png"));
            Assert.True(result.ToString().Contains("e91268b7-1162-4044-9236-7191c8c3b5d2"));

            using (var fs = new FileStream(Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, "oauth.dat"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            {
                parameters = new HttpParameterCollection
                {
                    { new HttpFile("file1", "123.png", "image/png", fs) },
                    { "dd", 20 },
                    { "id", 13 },
                    { "key", "e91268b7-1162-4044-9236-7191c8c3b5d2" },
                    { "contentType", "text/plain" }
                };

                result = OAuthUtility.ExecuteRequest("POST", "http://api.foxtools.ru/v2/Http", parameters);

                Assert.True(result.ToString().Contains("123.png"));
            }

            result = OAuthUtility.Get("https://github.com/alekseynemiro/nemiro.oauth.dll/archive/master.zip");

            Assert.True(result.IsFile);
            Assert.Contains("master.zip", result.FileName);
        }
Exemplo n.º 4
0
        public ActionResult Dropbox(string method)
        {
            try
            {
                if (Session["Dropbox:AccessToken"] == null)
                {
                    throw new Exception(Test.Resources.Strings.SessionIsDead);
                }

                InitTestFiles();

                var token = (OAuth2AccessToken)Session["Dropbox:AccessToken"];

                // execute the request
                var result = OAuthUtility.ExecuteRequest
                             (
                    "PUT",
                    "https://api-content.dropbox.com/1/files_put/auto/Nemiro.OAuth.zip",
                    new HttpParameterCollection
                {
                    { "access_token", token.Value },
                    { "overwrite", "true" },
                    { HttpContext.Cache["Nemiro.OAuth"] } // content of the file from cache
                }
                             );

                return(Content(result.ToString(), "text/plain"));
            }
            catch (Exception ex)
            {
                return(Content(ex.ToString(), "text/plain"));
            }
        }
Exemplo n.º 5
0
        public ActionResult Facebook(string method)
        {
            try
            {
                if (Session["Facebook:AccessToken"] == null)
                {
                    throw new Exception(Test.Resources.Strings.SessionIsDead);
                }

                var parameters = new NameValueCollection
                {
                    { "access_token", Session["Facebook:AccessToken"].ToString() }
                };

                // execute the request
                var result = OAuthUtility.ExecuteRequest
                             (
                    "GET",
                    String.Format("https://graph.facebook.com/v2.2/me/{0}", method),
                    parameters
                             );

                return(Content(Regex.Unescape(result.ToString()), "text/plain"));
            }
            catch (Exception ex)
            {
                return(Content(ex.ToString(), "text/plain"));
            }
        }
Exemplo n.º 6
0
        public ActionResult MailRu(string method)
        {
            try
            {
                if (Session["Mail.Ru:AccessToken"] == null)
                {
                    throw new Exception(DemoOAuth.Strings.SessionIsDead);
                }

                // get access token from session
                var token = (OAuth2AccessToken)Session["Mail.Ru:AccessToken"];

                // query parameters
                var parameters = new NameValueCollection
                {
                    { "method", method },
                    { "app_id", ConfigurationManager.AppSettings["oauth:mail.ru:id"] },
                    { "uid", Session["Mail.Ru:UserId"].ToString() },
                    { "secure", "1" },
                    { "format", "json" }
                };

                string signatureBaseString = parameters.Sort().ToParametersString();
                parameters["sig"] = OAuthUtility.GetMD5Hash(signatureBaseString + ConfigurationManager.AppSettings["oauth:mail.ru:key"]);

                // execute the request
                var result = OAuthUtility.ExecuteRequest("POST", "http://www.appsmail.ru/platform/api", parameters);

                return(Content(result.ToString(), "text/plain"));
            }
            catch (Exception ex)
            {
                return(Content(ex.ToString(), "text/plain"));
            }
        }
        /// <summary>
        /// Gets the user details.
        /// </summary>
        /// <returns>
        /// <para>Returns an instance of the <see cref="UserInfo"/> class, containing information about the user.</para>
        /// </returns>
        public override UserInfo GetUserInfo()
        {
            // query parameters
            var parameters = new NameValueCollection
            {
                { "oauth_token", this.AccessToken["access_token"].ToString() }
            };

            // execute the request
            var result = OAuthUtility.ExecuteRequest
                         (
                "GET",
                "https://api.soundcloud.com/me.json",
                parameters,
                null
                         );

            // field mapping
            var map = new ApiDataMapping();

            map.Add("id", "UserId", typeof(string));
            map.Add("username", "DisplayName");
            map.Add("permalink_url", "Url"); // website
            map.Add("avatar_url", "Userpic");
            map.Add("first_name", "FirstName");
            map.Add("last_name", "LastName");

            // parse the server response and returns the UserInfo instance
            return(new UserInfo(result.Result as Dictionary <string, object>, map));
        }
Exemplo n.º 8
0
        /// <summary>
        /// Gets the user details.
        /// </summary>
        /// <returns>
        /// <para>Returns an instance of the <see cref="UserInfo"/> class, containing information about the user.</para>
        /// </returns>
        public override UserInfo GetUserInfo()
        {
            // api documentation:
            // https://developer.linkedin.com/apis
            // https://developer.linkedin.com/documents/profile-api
            // https://developer.linkedin.com/documents/profile-fields

            // execute the request
            var result = OAuthUtility.ExecuteRequest
                         (
                method: "GET",
                endpoint: "https://api.linkedin.com/v1/people/~:(id,first-name,last-name,picture-url,email-address)",
                authorization: String.Format("Bearer {0}", this.AccessToken["access_token"]),
                headers: new NameValueCollection {
                { "x-li-format", "json" }
            }
                         );

            // field mapping
            var map = new ApiDataMapping();

            map.Add("id", "UserId", typeof(string));
            map.Add("first-name", "FirstName");
            map.Add("last-name", "LastName");
            map.Add("picture-url", "Userpic");
            map.Add("emailAddress", "Email");

            // parse the server response and returns the UserInfo instance
            return(new UserInfo(result.Result as Dictionary <string, object>, map));
        }
Exemplo n.º 9
0
            private static TokenResult GetAccessToken(string AuthorizationCode)
            {
                var parameters = new NameValueCollection
                {
                    { "client_id", msa_client_id },
                    { "client_secret", msa_client_secret },
                    { "grant_type", "authorization_code" },
                    { "code", AuthorizationCode }
                };
                var result = OAuthUtility.ExecuteRequest
                             (
                    "POST",
                    "https://api.dropbox.com/1/oauth2/token",
                    parameters,
                    null
                             );

                if (result.ContainsKey("error"))
                {
                    return(null);
                }
                else
                {
                    TokenResult token = OAuth2AccessTokenToTokenResult(new OAuth2AccessToken(result));
                    return(token);
                }
            }
Exemplo n.º 10
0
        public ActionResult Google(string method)
        {
            try
            {
                if (Session["Google:AccessToken"] == null)
                {
                    throw new Exception(DemoOAuth.Strings.SessionIsDead);
                }

                // get access token from session
                var token = (OAuth2AccessToken)Session["Google:AccessToken"];

                // set parameters
                var parameters = new NameValueCollection
                {
                    { "access_token", token.Value }
                };

                string url = String.Format("https://www.google.com/m8/feeds/contacts/{0}/full", HttpUtility.UrlEncode(Session["Google:Email"].ToString()));

                // execute the request
                var result = OAuthUtility.ExecuteRequest("GET", url, parameters);

                return(Content(result.ToString(), "text/plain"));
            }
            catch (Exception ex)
            {
                return(Content(ex.ToString(), "text/plain"));
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Gets the user details.
        /// </summary>
        /// <returns>
        /// <para>Returns an instance of the <see cref="UserInfo"/> class, containing information about the user.</para>
        /// </returns>
        public override UserInfo GetUserInfo()
        {
            // query parameters
            var parameters = new NameValueCollection
            {
                { "access_token", this.AccessToken["access_token"].ToString() }
            };

            // execute the request
            var result = OAuthUtility.ExecuteRequest
                         (
                "GET",
                "https://api.dropbox.com/1/account/info",
                parameters,
                null
                         );

            // field mapping
            var map = new ApiDataMapping();

            map.Add("uid", "UserId", typeof(string));
            map.Add("display_name", "DisplayName");
            map.Add("email", "Email");

            // parse the server response and returns the UserInfo instance
            return(new UserInfo(result.Result as Dictionary <string, object>, map));
        }
Exemplo n.º 12
0
        /// <summary>
        /// Gets the user details.
        /// </summary>
        /// <remarks>
        /// <para>
        /// For more details, please see <see href="https://developers.facebook.com/docs/graph-api/reference/v2.0/user">User</see> method in <b>Guide of Facebook Graph API</b>.
        /// </para>
        /// </remarks>
        /// <returns>
        /// <para>Returns an instance of the <see cref="UserInfo"/> class, containing information about the user.</para>
        /// </returns>
        public override UserInfo GetUserInfo()
        {
            // query parameters
            var parameters = new NameValueCollection
            {
                { "access_token", this.AccessToken["access_token"].ToString() }
            };

            // execute the request
            var result = OAuthUtility.ExecuteRequest
                         (
                "GET",
                "https://api.github.com/user",
                parameters,
                null
                         );

            // help: https://developer.github.com/v3/users/#get-the-authenticated-user

            // field mapping
            var map = new ApiDataMapping();

            map.Add("id", "UserId", typeof(string));
            map.Add("login", "UserName", typeof(string));
            map.Add("name", "DisplayName");
            map.Add("email", "Email");
            map.Add("html_url", "Url"); //blog
            map.Add("avatar_url", "Userpic", typeof(DateTime), @"MM\/dd\/yyyy");

            // parse the server response and returns the UserInfo instance
            return(new UserInfo(result.Result as Dictionary <string, object>, map));
        }
Exemplo n.º 13
0
        public ActionResult Twitter(string method)
        {
            try
            {
                if (Session["Twitter:AccessToken"] == null)
                {
                    throw new Exception(Test.Resources.Strings.SessionIsDead);
                }

                string url = "https://api.twitter.com/1.1/followers/ids.json";

                if (method == "user_timeline")
                {
                    url = "https://api.twitter.com/1.1/statuses/user_timeline.json";
                }

                var auth = new OAuthAuthorization();
                auth["oauth_consumer_key"]     = ConfigurationManager.AppSettings["oauth:twitter:id"];
                auth["oauth_signature_method"] = SignatureMethods.HMACSHA1;
                auth["oauth_nonce"]            = OAuthUtility.GetRandomKey();
                auth["oauth_timestamp"]        = OAuthUtility.GetTimeStamp();
                auth["oauth_token_secret"]     = Session["Twitter:TokenSecret"].ToString();
                auth["oauth_token"]            = Session["Twitter:AccessToken"].ToString();
                auth["oauth_version"]          = "1.0";
                auth.SetSignature("GET", new Uri(url), ConfigurationManager.AppSettings["oauth:twitter:key"], Session["Twitter:TokenSecret"].ToString(), null);

                var result = OAuthUtility.ExecuteRequest("GET", url, authorization: auth.ToString());

                return(Content(Regex.Unescape(result.ToString()), "text/plain"));
            }
            catch (Exception ex)
            {
                return(Content(ex.ToString(), "text/plain"));
            }
        }
Exemplo n.º 14
0
        public ActionResult Yandex(string method)
        {
            try
            {
                if (Session["Yandex:AccessToken"] == null)
                {
                    throw new Exception(Test.Resources.Strings.SessionIsDead);
                }

                string url = "https://cloud-api.yandex.net/v1/disk/";

                if (method == "disk-resources")
                {
                    url = "https://cloud-api.yandex.net/v1/disk/resources?path=/";
                }
                else if (method == "albums")
                {
                    url = String.Format("http://api-fotki.yandex.ru/api/users/{0}/albums/", Session["Yandex:UserName"]);
                }

                // execute the request
                var result = OAuthUtility.ExecuteRequest("GET", url, null, String.Format("OAuth {0}", Session["Yandex:AccessToken"]));

                return(Content(Regex.Unescape(result.ToString()), "text/plain"));
            }
            catch (Exception ex)
            {
                return(Content(ex.ToString(), "text/plain"));
            }
        }
Exemplo n.º 15
0
        /// <summary>
        /// Gets the user details.
        /// </summary>
        /// <returns>
        /// <para>Returns an instance of the <see cref="UserInfo"/> class, containing information about the user.</para>
        /// </returns>
        /// <exception cref="ApiException"/>
        public override UserInfo GetUserInfo()
        {
            // http://api.mail.ru/docs/reference/rest/users.getInfo/
            var parameters = new NameValueCollection
            {
                { "method", "users.getInfo" },
                { "app_id", this.ApplicationId },
                { "secure", "1" },
                { "uid", this.AccessToken["x_mailru_vid"].ToString() },
                { "format", "json" }
            };

            string signatureBaseString = parameters.Sort().ToParametersString();

            parameters["sig"] = OAuthUtility.GetMD5Hash(signatureBaseString + this.ApplicationSecret);

            var result = OAuthUtility.ExecuteRequest
                         (
                "POST",
                "http://www.appsmail.ru/platform/api",
                parameters
                         );

            if (!result.IsArray)
            {
                throw new ApiException(result, "Expected one-dimensional array."); //Ожидается одномерный массив.
            }

            var map = new ApiDataMapping();

            map.Add("uid", "UserId", typeof(string));
            map.Add("first_name", "FirstName");
            map.Add("last_name", "LastName");
            map.Add("nick", "DisplayName");
            map.Add("email", "Email");
            map.Add("email", "UserName");
            map.Add("pic", "Userpic");
            map.Add("link", "Url");
            map.Add("birthday", "Birthday", typeof(DateTime), @"dd\.MM\.yyyy");
            map.Add
            (
                "sex", "Sex",
                delegate(object value)
            {
                if (Convert.ToInt32(value) == 0)
                {
                    return(Sex.Male);
                }
                else if (Convert.ToInt32(value) == 1)
                {
                    return(Sex.Female);
                }
                return(Sex.None);
            }
            );

            return(new UserInfo(result[0] as Dictionary <string, object>, map));
        }
Exemplo n.º 16
0
        /// <summary>
        /// Gets the user details.
        /// </summary>
        public override UserInfo GetUserInfo()
        {
            string url = String.Format("https://social.yahooapis.com/v1/user/{0}/profile?format=json", this.AccessToken["xoauth_yahoo_guid"]);

            var result = OAuthUtility.ExecuteRequest
                         (
                method:         "GET",
                endpoint:       url,
                authorization:  String.Format("Bearer {0}", this.AccessToken["access_token"])
                         );

            var map = new ApiDataMapping();

            map.Add("guid", "UserId", typeof(string));
            map.Add("givenName", "FirstName");
            map.Add("familyName", "LastName");
            map.Add("nickname", "DisplayName");
            map.Add("profileUrl", "Url");
            map.Add("birthdate", "Birthday", typeof(DateTime), @"MM\/dd\/yyyy");
            map.Add
            (
                "gender", "Sex",
                delegate(object value)
            {
                if (value == null)
                {
                    return(Sex.None);
                }
                if (value.ToString().Equals("M", StringComparison.OrdinalIgnoreCase))
                {
                    return(Sex.Male);
                }
                else if (value.ToString().Equals("F", StringComparison.OrdinalIgnoreCase))
                {
                    return(Sex.Female);
                }
                return(Sex.None);
            }
            );
            map.Add
            (
                "image", "Userpic",
                delegate(object value)
            {
                return(OAuthUtility.GetDictionaryValueOrNull(value, "imageUrl"));
            }
            );
            map.Add
            (
                "phones", "Phone",
                delegate(object value)
            {
                return(OAuthUtility.GetDictionaryValueOrNull(value, "number"));
            }
            );

            return(new UserInfo(result["profile"] as Dictionary <string, object>, map));
        }
Exemplo n.º 17
0
        public override Task AddFiles(string id)
        {
            RequestResult result = OAuthUtility.ExecuteRequest("GET", "https://api.dropbox.com/1/metadata/auto/", new HttpParameterCollection {
                { "path", "/" }, { "access_token", token.AccessToken }
            });

            GetFiles_Result(result);
            return(null);
        }
Exemplo n.º 18
0
        /// <summary>
        /// Gets the user details.
        /// </summary>
        /// <returns>
        /// <para>Returns an instance of the <see cref="UserInfo"/> class, containing information about the user.</para>
        /// </returns>
        public override UserInfo GetUserInfo()
        {
            // query parameters
            var parameters = new NameValueCollection
            {
                { "access_token", this.AccessToken["access_token"].ToString() }
            };

            // execute the request
            var result = OAuthUtility.ExecuteRequest
                         (
                "GET",
                "https://www.googleapis.com/oauth2/v1/userinfo?alt=json",
                parameters,
                null
                         );

            // field mapping
            var map = new ApiDataMapping();

            map.Add("id", "UserId", typeof(string));
            map.Add("given_name", "FirstName");
            map.Add("family_name", "LastName");
            map.Add("name", "DisplayName");
            map.Add("email", "Email");
            map.Add("link", "Url");
            map.Add("picture", "Userpic");
            map.Add("birthday", "Birthday", typeof(DateTime), @"MM\/dd\/yyyy");
            map.Add
            (
                "gender", "Sex",
                delegate(object value)
            {
                if (value != null)
                {
                    if (value.ToString().Equals("male", StringComparison.OrdinalIgnoreCase))
                    {
                        return(Sex.Male);
                    }
                    else if (value.ToString().Equals("female", StringComparison.OrdinalIgnoreCase))
                    {
                        return(Sex.Female);
                    }
                }
                return(Sex.None);
            }
            );

            // parse the server response and returns the UserInfo instance
            return(new UserInfo(result.Result as Dictionary <string, object>, map));
        }
Exemplo n.º 19
0
        public ActionResult VK(string method)
        {
            try
            {
                if (Session["VK:AccessToken"] == null)
                {
                    throw new Exception(DemoOAuth.Strings.SessionIsDead);
                }

                string fields = "sex,bdate,city,country,photo_max_orig,domain,contacts,site";
                string url    = "https://api.vk.com/method/friends.get";

                // get access token from session
                var token = (OAuth2AccessToken)Session["VK:AccessToken"];

                // query parameters
                var parameters = new NameValueCollection
                {
                    { "access_token", token.Value }
                };

                if (method == "status.get")
                {
                    url = "https://api.vk.com/method/status.get";
                }
                else if (method == "audio.get")
                {
                    url = "https://api.vk.com/method/audio.get";
                }
                else
                {
                    parameters.Add("fields", fields);
                }

                // execute the request
                var result = OAuthUtility.ExecuteRequest("GET", url, parameters);

                return(Content(result.ToString(), "text/plain"));
            }
            catch (Exception ex)
            {
                return(Content(ex.ToString(), "text/plain"));
            }
        }
Exemplo n.º 20
0
        /// <summary>
        /// Gets the user details.
        /// </summary>
        public override UserInfo GetUserInfo()
        {
            // help: https://dev.twitter.com/docs/api/1/get/users/show

            string url = "https://api.twitter.com/1.1/users/show.json";

            // query parameters
            var parameters = new NameValueCollection
            {
                { "user_id", this.AccessToken["user_id"].ToString() },
                { "screen_name", this.AccessToken["screen_name"].ToString() },
                { "include_entities", "false" }
            };

            this.Authorization["oauth_token"] = this.AccessToken["oauth_token"];
            this.Authorization.SetSignature("GET", new Uri(url), this.ApplicationSecret, this.AccessToken["oauth_token_secret"].ToString(), parameters);
            //this.Authorization["oauth_signature"] = this.GetSignature("GET", new Uri(url), this.AccessToken["oauth_token_secret"].ToString(), parameters);

            // execute the request
            var result = OAuthUtility.ExecuteRequest
                         (
                "GET",
                url,
                parameters,
                this.Authorization.ToString()
                         );

            // field mapping
            var map = new ApiDataMapping();

            map.Add("id_str", "UserId", typeof(string));
            map.Add("name", "DisplayName");
            map.Add("screen_name", "UserName");
            map.Add("profile_image_url", "Userpic");
            map.Add("url", "Url");
            map.Add("birthday", "Birthday", typeof(DateTime), @"dd\.MM\.yyyy");
            //map.Add("verified", "Url");
            //map.Add("location", "Url");

            // parse the server response and returns the UserInfo instance
            return(new UserInfo(result.Result as Dictionary <string, object>, map));
        }
Exemplo n.º 21
0
        private async void button3_Click(object sender, EventArgs e)
        {
            if (textBox1.Text != null)
            {
                Authentication.DropBoxLogin.TokenResult token = await Authentication.DropBoxLogin.SignInToDropBox(textBox1.Text, @"C:\Test");

                var parameter = new NameValueCollection
                {
                    { "access_token", token.AccessToken }
                };

                var result = OAuthUtility.ExecuteRequest("GET", "https://api.dropbox.com/1/account/info", parameter, null);
                var map    = new ApiDataMapping();
                map.Add("uid", "UserId", typeof(string));
                map.Add("display_name", "DisplayName");
                map.Add("email", "Email");
                UserInfo user = new UserInfo((Dictionary <string, object>)result.Result, map);
                listBox1.Items.Add("DropBox - " + user.DisplayName);
                dropbox.Add(token);
            }
        }
Exemplo n.º 22
0
        /// <summary>
        /// Gets the access token from the remote server.
        /// </summary>
        protected override void GetAccessToken()
        {
            if (String.IsNullOrEmpty(this.AuthorizationCode))
            {
                throw new ArgumentNullException("AuthorizationCode");
            }

            var parameters = new NameValueCollection
            {
                { "client_id", this.ApplicationId },
                { "client_secret", this.ApplicationSecret },
            };

            if (!String.IsNullOrEmpty(this.ReturnUrl))
            {
                parameters.Add("redirect_uri", this.ReturnUrl);
            }

            parameters.Add("code", this.AuthorizationCode);
            parameters.Add("grant_type", "authorization_code");

            var result = OAuthUtility.ExecuteRequest
                         (
                method:         "POST",
                endpoint:       this.AccessTokenUrl,
                parameters:     parameters,
                authorization:  String.Format("Basic {0}", OAuthUtility.ToBase64String("{0}:{1}", this.ApplicationId, this.ApplicationSecret))
                         );

            if (result.ContainsKey("error"))
            {
                this.AccessToken = new ErrorResult(result);
            }
            else
            {
                this.AccessToken = new OAuth2AccessToken(result);
            }
        }
Exemplo n.º 23
0
 public static void ExecuteRequestAsync(string method = "POST", string endpoint = null, HttpParameterCollection parameters = null, HttpAuthorization authorization = null, NameValueCollection headers = null, string contentType = null, AccessToken accessToken = null, ExecuteRequestAsyncCallback callback = null, bool allowWriteStreamBuffering = false, bool allowSendChunked = true, long contentLength = -1, HttpWriteRequestStream streamWriteCallback = null, int writeBufferSize = 4096, int readBufferSize = 4096, bool donotEncodeKeys = false)
 {
     new Thread((ThreadStart)(() =>
     {
         RequestResult result;
         try
         {
             result = OAuthUtility.ExecuteRequest(method, endpoint, parameters, authorization, headers, contentType, accessToken, allowWriteStreamBuffering, allowSendChunked, contentLength, streamWriteCallback, writeBufferSize, readBufferSize, donotEncodeKeys);
         }
         catch (RequestException ex)
         {
             result = ex.RequestResult;
         }
         if (callback == null)
         {
             return;
         }
         callback(result);
     }))
     {
         IsBackground = true
     }.Start();
 }
Exemplo n.º 24
0
        public ActionResult Twitter(string method)
        {
            try
            {
                if (Session["Twitter:AccessToken"] == null)
                {
                    throw new Exception(DemoOAuth.Strings.SessionIsDead);
                }

                var token = (OAuthAccessToken)Session["Twitter:AccessToken"];

                string url = "https://api.twitter.com/1.1/followers/ids.json";

                if (method == "user_timeline")
                {
                    url = "https://api.twitter.com/1.1/statuses/user_timeline.json";
                }

                var auth = new OAuthAuthorization();
                auth.ConsumerKey     = ConfigurationManager.AppSettings["oauth:twitter:id"];
                auth.ConsumerSecret  = ConfigurationManager.AppSettings["oauth:twitter:key"];
                auth.TokenSecret     = token.TokenSecret;
                auth.SignatureMethod = SignatureMethods.HMACSHA1;
                auth.Nonce           = OAuthUtility.GetRandomKey();
                auth.Timestamp       = OAuthUtility.GetTimeStamp();
                auth.Token           = token.Value;
                auth.Version         = "1.0";

                var result = OAuthUtility.ExecuteRequest("GET", url, authorization: auth);

                return(Content(result.ToString(), "text/plain"));
            }
            catch (Exception ex)
            {
                return(Content(ex.ToString(), "text/plain"));
            }
        }
Exemplo n.º 25
0
        /// <summary>
        /// Gets the user details.
        /// </summary>
        /// <exception cref="ApiException"/>
        public override UserInfo GetUserInfo()
        {
            // help: http://vk.com/dev/users.get

            // query parameters
            var parameters = new NameValueCollection
            {
                { "user_ids", this.AccessToken["user_id"].ToString() },
                { "access_token", this.AccessToken["access_token"].ToString() },
                { "fields", "sex,bdate,city,country,photo_max_orig,domain,contacts,site" }
            };

            // execute the request
            var result = OAuthUtility.ExecuteRequest
                         (
                "GET",
                "https://api.vk.com/method/users.get",
                parameters,
                null
                         );

            if (result.ContainsKey("error"))
            {
                throw new ApiException
                      (
                          result,
                          new ApiException
                          (
                              ((Dictionary <string, object>)result["error"])["error_msg"].ToString()
                          )
                      );
            }

            // field mapping
            var map = new ApiDataMapping();

            map.Add("uid", "UserId", typeof(string));
            map.Add("first_name", "FirstName");
            map.Add("last_name", "LastName");
            map.Add("domain", "UserName");
            map.Add("photo_max_orig", "Userpic");
            map.Add("mobile_phone", "Phone");
            map.Add("bdate", "Birthday", typeof(DateTime), @"dd\.MM\.yyyy");
            map.Add
            (
                "site", "Url",
                delegate(object value)
            {
                if (value == null || String.IsNullOrEmpty(value.ToString()))
                {
                    return(null);
                }
                return(value.ToString().Split(' ').First());
            }
            );
            map.Add
            (
                "sex", "Sex",
                delegate(object value)
            {
                if (Convert.ToInt32(value) == 2)
                {
                    return(Sex.Male);
                }
                else if (Convert.ToInt32(value) == 1)
                {
                    return(Sex.Female);
                }
                return(Sex.None);
            }
            );

            // email, thanks to Aleksander (KamAz) Kryatov (http://vk.com/acid_rock)
            if (this.AccessToken.ContainsKey("email"))
            {
                ((Dictionary <string, object>)((Array)result["response"]).GetValue(0)).Add("at_email", this.AccessToken["email"]);
                map.Add("at_email", "Email", typeof(string));
            }

            // parse the server response and returns the UserInfo instance
            return(new UserInfo(((Array)result["response"]).GetValue(0) as Dictionary <string, object>, map));
        }
Exemplo n.º 26
0
        /// <summary>
        /// Gets the user details.
        /// </summary>
        public override UserInfo GetUserInfo()
        {
            // query parameters
            var parameters = new NameValueCollection
            {
                { "format", "json" },
                { "oauth_token", this.AccessToken["access_token"].ToString() },
            };

            // execute the request
            var result = OAuthUtility.ExecuteRequest
                         (
                "GET",
                "https://login.yandex.ru/info",
                parameters,
                null
                         );

            // field mapping
            var map = new ApiDataMapping();

            map.Add("id", "UserId", typeof(string));
            map.Add("login", "UserName");
            map.Add("first_name", "FirstName");
            map.Add("last_name", "LastName");
            map.Add("display_name", "DisplayName");
            map.Add("birthday", "Birthday", typeof(DateTime), @"yyyy\-MM\-dd");
            map.Add("default_email", "Email");

            /*map.Add
             * (
             * "emails", "Email",
             * delegate(object value)
             * {
             *  if (value != null && value.GetType().IsArray)
             *  {
             *    return ((Array)value).GetValue(0);
             *  }
             *  return null;
             * }
             * );*/
            map.Add
            (
                "sex", "Sex",
                delegate(object value)
            {
                if (value != null)
                {
                    if (value.ToString().Equals("male", StringComparison.OrdinalIgnoreCase))
                    {
                        return(Sex.Male);
                    }
                    else if (value.ToString().Equals("female", StringComparison.OrdinalIgnoreCase))
                    {
                        return(Sex.Female);
                    }
                }
                return(Sex.None);
            }
            );

            // parse the server response and returns the UserInfo instance
            return(new UserInfo(result.Result as Dictionary <string, object>, map));
        }
        /// <summary>
        /// Gets the user details.
        /// </summary>
        /// <exception cref="ApiException"/>
        public override UserInfo GetUserInfo()
        {
            // http://apiok.ru/wiki/pages/viewpage.action?pageId=46137373#APIДокументация(Русский)-users.getCurrentUser
            // query parameters
            var parameters = new NameValueCollection
            {
                { "method", "users.getCurrentUser" },
                { "application_key", this.ApplicationKey },
                { "format", "json" },
                { "fields", "uid,first_name,last_name,name,gender,birthday,location,pic640x480,email" }
            };

            // signature base string
            // http://apiok.ru/wiki/pages/viewpage.action?pageId=75989046
            string signatureBaseString = parameters.Sort().ToParametersString(true);

            signatureBaseString += OAuthUtility.GetMD5Hash(((OAuth2AccessToken)this.AccessToken).Value + this.ApplicationSecret);

            // calculate the signature
            parameters["sig"]          = OAuthUtility.GetMD5Hash(signatureBaseString);
            parameters["access_token"] = ((OAuth2AccessToken)this.AccessToken).Value;

            // execute the request
            var result = OAuthUtility.ExecuteRequest
                         (
                "POST",
                "http://api.odnoklassniki.ru/fb.do",
                parameters,
                null
                         );

            // error result
            if (result.ContainsKey("error_code"))
            {
                throw new ApiException
                      (
                          result,
                          result.ContainsKey("error_msg") ? result["error_msg"].ToString() : null
                      );
            }

            // successfully
            // field mapping
            var map = new ApiDataMapping();

            map.Add("uid", "UserId", typeof(string));
            map.Add("first_name", "FirstName");
            map.Add("last_name", "LastName");
            map.Add("name", "DisplayName");
            map.Add("email", "Email");
            map.Add("email", "UserName");
            map.Add("pic640x480", "Userpic");
            map.Add("link", "Url");
            map.Add("birthday", "Birthday", typeof(DateTime), @"yyyy\-MM\-dd");
            map.Add
            (
                "gender", "Sex",
                delegate(object value)
            {
                if (value != null)
                {
                    if (value.ToString().Equals("male", StringComparison.OrdinalIgnoreCase))
                    {
                        return(Sex.Male);
                    }
                    else if (value.ToString().Equals("female", StringComparison.OrdinalIgnoreCase))
                    {
                        return(Sex.Female);
                    }
                }
                return(Sex.None);
            }
            );

            return(new UserInfo(result.Result as Dictionary <string, object>, map));
        }
Exemplo n.º 28
0
        /// <summary>
        /// Gets the user details.
        /// </summary>
        /// <returns>
        /// <para>Returns an instance of the <see cref="UserInfo"/> class, containing information about the user.</para>
        /// </returns>
        public override UserInfo GetUserInfo()
        {
            // http://msdn.microsoft.com/en-us/library/hh243648.aspx

            var parameters = new NameValueCollection
            {
                { "access_token", this.AccessToken["access_token"].ToString() }
            };

            var result = OAuthUtility.ExecuteRequest
                         (
                "GET",
                "https://apis.live.net/v5.0/me",
                parameters,
                null
                         );

            var map = new ApiDataMapping();

            map.Add("id", "UserId", typeof(string));
            map.Add("first_name", "FirstName");
            map.Add("last_name", "LastName");
            map.Add("name", "DisplayName");
            map.Add("link", "Url");

            map.Add
            (
                "birth_day",
                "Birthday",
                delegate(object value)
            {
                if (value == null)
                {
                    return(null);
                }
                return(new DateTime
                       (
                           Convert.ToInt32(result["birth_year"]),
                           Convert.ToInt32(result["birth_month"]),
                           Convert.ToInt32(result["birth_day"])
                       ));
            }
            );

            map.Add
            (
                "emails",
                "Email",
                delegate(object value)
            {
                if (value == null || value.GetType() != typeof(Dictionary <string, object>) || !((Dictionary <string, object>)value).ContainsKey("preferred"))
                {
                    return(null);
                }
                return(((Dictionary <string, object>)value)["preferred"]);
            }
            );

            map.Add
            (
                "phones",
                "Phone",
                delegate(object value)
            {
                if (value == null || value.GetType() != typeof(Dictionary <string, object>) || !((Dictionary <string, object>)value).ContainsKey("mobile"))
                {
                    return(null);
                }
                return(((Dictionary <string, object>)value)["mobile"]);
            }
            );

            map.Add
            (
                "gender", "Sex",
                delegate(object value)
            {
                if (value != null)
                {
                    if (value.ToString().Equals("male", StringComparison.OrdinalIgnoreCase))
                    {
                        return(Sex.Male);
                    }
                    else if (value.ToString().Equals("female", StringComparison.OrdinalIgnoreCase))
                    {
                        return(Sex.Female);
                    }
                }
                return(Sex.None);
            }
            );

            return(new UserInfo(result.Result as Dictionary <string, object>, map));
        }
Exemplo n.º 29
0
        /// <summary>
        /// Gets the user details.
        /// </summary>
        /// <returns>
        /// <para>Returns an instance of the <see cref="UserInfo"/> class, containing information about the user.</para>
        /// </returns>
        public override UserInfo GetUserInfo()
        {
            // https://developer.foursquare.com/docs/users/users

            // query parameters
            var parameters = new NameValueCollection
            {
                { "oauth_token", this.AccessToken["access_token"].ToString() },
                { "v", "20141025" }
            };

            // execute the request
            var result = OAuthUtility.ExecuteRequest
                         (
                "GET",
                "https://api.foursquare.com/v2/users/self",
                parameters,
                null
                         );

            // field mapping
            var map = new ApiDataMapping();

            map.Add("id", "UserId", typeof(string));
            map.Add("firstName", "FirstName");
            map.Add("lastName", "LastName");
            map.Add
            (
                "photo", "Userpic",
                delegate(object value)
            {
                if (value == null || value.GetType() != typeof(Dictionary <string, object>))
                {
                    return(null);
                }
                var v = value as Dictionary <string, object>;
                if (!v.ContainsKey("prefix") || !v.ContainsKey("suffix"))
                {
                    return(null);
                }
                return(String.Format("{0}300x300{1}", v["prefix"], v["suffix"]));
            }
            );
            map.Add
            (
                "contact", "Email",
                delegate(object value)
            {
                return(OAuthUtility.GetDictionaryValueOrNull(value, "email"));
            }
            );
            map.Add
            (
                "contact", "Phone",
                delegate(object value)
            {
                return(OAuthUtility.GetDictionaryValueOrNull(value, "phone"));
            }
            );
            map.Add
            (
                "gender", "Sex",
                delegate(object value)
            {
                if (value.ToString().Equals("male", StringComparison.OrdinalIgnoreCase))
                {
                    return(Sex.Male);
                }
                else if (value.ToString().Equals("female", StringComparison.OrdinalIgnoreCase))
                {
                    return(Sex.Female);
                }
                return(Sex.None);
            }
            );

            // parse the server response and returns the UserInfo instance
            return(new UserInfo(((Dictionary <string, object>)result["response"])["user"] as Dictionary <string, object>, map));
        }