コード例 #1
0
        JsonValue GetUserProfile(JsonValue token)
        {
            // get the user info
            JsonValue userProfile = null;

            using (WebRequest request = new WebRequest("https://www.googleapis.com/oauth2/v1/userinfo?alt=json&access_token=" + HttpUtility.UrlEncode((string)token["access_token"]), allowAutoRedirect: true)) {
                HttpClientResponse response = request.GetResponse();
                if (response.StatusCode == 200)
                {
                    userProfile = response.ReadAsJson();
                }
            }
            return(userProfile);
        }
コード例 #2
0
        JsonValue GetUserProfile(JsonValue token)
        {
            // get the user info API: https://developers.facebook.com/docs/reference/api/user/
            JsonValue userProfile = null;

            using (WebRequest request = new WebRequest(
                       "https://graph.facebook.com/me?access_token=" + HttpUtility.UrlEncode((string)token["access_token"]) +
                       "&fields=picture,first_name,last_name", allowAutoRedirect: true)) {
                HttpClientResponse response = request.GetResponse();
                if (response.StatusCode == 200)
                {
                    userProfile = response.ReadAsJson();
                }
            }
            return(userProfile);
        }
コード例 #3
0
ファイル: Main.cs プロジェクト: PlumpMath/liberasme-cloud-cil
        public static bool TestMessageServiceSearch()
        {
            bool done = false;

            using (HttpClient client = HttpClient.Create("localhost", 3333)) {
                HttpClientRequest request = new HttpClientRequest();
                request.Method = "GET";
                request.Path   = "/message";
                request.QueryString["user"] = "******";
                client.SendRequest(request);
                HttpClientResponse response = client.GetResponse();
                if (response.StatusCode == 200)
                {
                    JsonValue json = response.ReadAsJson();
                    done = (json.Count == 1);
                }
            }
            return(done);
        }
コード例 #4
0
        JsonValue GetTokenFromCode(string code)
        {
            // get the access token
            JsonValue token = null;

            using (WebRequest request = new WebRequest("https://accounts.google.com/o/oauth2/token", allowAutoRedirect: true)) {
                request.Method = "POST";
                request.Headers["content-type"] = "application/x-www-form-urlencoded";
                request.Content = new StringContent(
                    "code=" + HttpUtility.UrlEncode(code) + "&" +
                    "client_id=" + HttpUtility.UrlEncode(ClientId) + "&" +
                    "client_secret=" + HttpUtility.UrlEncode(ClientSecret) + "&" +
                    "redirect_uri=" + HttpUtility.UrlEncode(RedirectUri) + "&" +
                    "grant_type=authorization_code");
                HttpClientResponse response = request.GetResponse();
                if (response.StatusCode == 200)
                {
                    token = response.ReadAsJson();
                }
            }
            return(token);
        }
コード例 #5
0
ファイル: Main.cs プロジェクト: PlumpMath/liberasme-cloud-cil
        public static bool TestMessageService()
        {
            bool done = false;

            using (HttpClient client = HttpClient.Create("localhost", 3333)) {
                HttpClientRequest request = new HttpClientRequest();
                request.Method = "POST";
                request.Path   = "/message";
                JsonValue content = new JsonObject();
                content["origin"]      = 1;
                content["destination"] = 2;
                content["type"]        = "message";
                content["content"]     = "Hello user 2";
                request.Content        = new JsonContent(content);
                client.SendRequest(request);
                HttpClientResponse response = client.GetResponse();
                if (response.StatusCode == 200)
                {
                    JsonValue json = response.ReadAsJson();
                    done = (json["origin"] == 1) && (json["destination"] == 2);
                }
            }
            return(done);
        }