Example #1
0
        protected override IDictionary<string, string> GetUserData(string accessToken)
        {
            var openid = GetOpenid(accessToken);
            var url = (UserInfoEndpoint + "?" + accessToken)
                .AddQueryParam("openid", openid)
                .AddQueryParam("oauth_consumer_key", this.appId)
                .AddQueryParam("format", "json");

            var text = WebRequestExtensions.Get(url);
            var graphData = JsonHelper.Deserialize<TencentGraphData>(text);

            var dictionary = new Dictionary<string, string>();
            dictionary.AddItemIfNotEmpty("id", openid);
            dictionary.AddItemIfNotEmpty("username", graphData.NickName);
            dictionary.AddItemIfNotEmpty("name", graphData.NickName);
            //dictionary.AddItemIfNotEmpty("msg", graphData.Msg);
            //dictionary.AddItemIfNotEmpty("gender", graphData.Gender);
            //dictionary.AddItemIfNotEmpty("figureurl", graphData.Figureurl);
            //dictionary.AddItemIfNotEmpty("figureurl_1", graphData.Figureurl_1);
            //dictionary.AddItemIfNotEmpty("figureurl_2", graphData.Figureurl_2);
            //dictionary.AddItemIfNotEmpty("figureurl_qq_1", graphData.Figureurl_qq_1);
            //dictionary.AddItemIfNotEmpty("figureurl_qq_2", graphData.Figureurl_qq_2);
            //dictionary.AddItemIfNotEmpty("is_yellow_vip", graphData.Is_yellow_vip.ToString());
            //dictionary.AddItemIfNotEmpty("vip", graphData.Vip.ToString());
            //dictionary.AddItemIfNotEmpty("level", graphData.Level.ToString());
            return dictionary;
        }
Example #2
0
		/// <summary>
		/// Gets the extra data obtained from the response message when authentication is successful.
		/// </summary>
		/// <param name="response">
		/// The response message. 
		/// </param>
		/// <returns>
		/// </returns>
		protected override Dictionary<string, string> GetExtraData(IAuthenticationResponse response) {
			FetchResponse fetchResponse = response.GetExtension<FetchResponse>();
			if (fetchResponse != null) {
				var extraData = new Dictionary<string, string>();
				extraData.AddItemIfNotEmpty("email", fetchResponse.GetAttributeValue(WellKnownAttributes.Contact.Email));
				extraData.AddItemIfNotEmpty("fullName", fetchResponse.GetAttributeValue(WellKnownAttributes.Name.FullName));

				return extraData;
			}

			return null;
		}
Example #3
0
        protected override IDictionary<string, string> GetUserData(string accessToken)
        {
            var dict = new Dictionary<string, string> { { "access_token", accessToken } };
            dynamic graphData;
            var text = WebRequestExtensions.Get(UserInfoEndpoint, dict);
            graphData = JsonHelper.Deserialize<dynamic>(text);

            var dictionary = new Dictionary<string, string>();
            dictionary.AddItemIfNotEmpty("id", graphData["response"]["id"].ToString() as string);
            dictionary.AddItemIfNotEmpty("username", graphData["response"]["name"] as string);
            dictionary.AddItemIfNotEmpty("name", graphData["response"]["name"] as string);
            //dictionary.AddItemIfNotEmpty("url", graphData["response"]["avatar"][1]["url"] as string);
            return dictionary;
        }
Example #4
0
        protected override IDictionary<string, string> GetUserData(string accessToken)
        {
            var dict = new Dictionary<string, string>();
            dict["access_token"] = accessToken;
            dict["format"] = "json";
            var json = WebRequestExtensions.Get(UserInfoEndpoint, dict);
            var result = JsonHelper.Deserialize<dynamic>(json);

            var dictionary = new Dictionary<string, string>();
            dictionary.AddItemIfNotEmpty("id", result["uid"] as string);
            dictionary.AddItemIfNotEmpty("username", result["name"] as string);
            dictionary.AddItemIfNotEmpty("name", result["name"] as string);
            return dictionary;
        }
Example #5
0
        protected override IDictionary<string, string> GetUserData(string accessToken)
        {
            var dict = new Dictionary<string, string>();
            dict["access_token"] = accessToken;
            dict["id"] = NeteaseModel.Uid;
            var text = WebRequestExtensions.Get(UserInfoEndpoint, dict);
            var graphData = JsonHelper.Deserialize<NeteaseGraphData>(text);

            var dictionary = new Dictionary<string, string>();
            dictionary.AddItemIfNotEmpty("id", graphData.Id);
            dictionary.AddItemIfNotEmpty("username", graphData.Name);
            dictionary.AddItemIfNotEmpty("name", graphData.Screen_Name);
            //dictionary.AddItemIfNotEmpty("url", graphData.Url);
            //dictionary.AddItemIfNotEmpty("gender", graphData.Gender.ToString());
            return dictionary;
        }
Example #6
0
        protected override IDictionary<string, string> GetUserData(string accessToken)
        {
            var dict = new Dictionary<string, string>();
            dict["access_token"] = accessToken;
            dict["uid"] = uid;
            var result = WebRequestExtensions.Get(UserData, dict);
            var graphData = JsonHelper.Deserialize<SinaGraphData>(result);
            var dictionary = new Dictionary<string, string>();
            dictionary.AddItemIfNotEmpty("id", graphData.Id);
            dictionary.AddItemIfNotEmpty("username", graphData.Screen_Name);
            dictionary.AddItemIfNotEmpty("name", graphData.Name);
            //foreach (var item in res)
            //{
            //    dictionary.AddItemIfNotEmpty(item.Key as string, item.Value.ToString() as string);
            //}

            return dictionary;
        }
Example #7
0
        protected override IDictionary<string, string> GetUserData(string accessToken)
        {
            GoogleUserData graph;
            var request = WebRequest.Create($"{_userInfoEndpoint}");
            request.Headers.Add(HttpRequestHeader.Authorization.ToString(), $"Bearer {accessToken}");
            using (var response = request.GetResponse())
            {
                using (var responseStream = response.GetResponseStream())
                {
                    graph = JsonHelper.Deserialize<GoogleUserData>(responseStream);
                }
            }

            var userData = new Dictionary<string, string>();
            userData.AddItemIfNotEmpty("id", graph.id);
            userData.AddItemIfNotEmpty("name", graph.name);
            userData.AddItemIfNotEmpty("given_name", graph.given_name);
            userData.AddItemIfNotEmpty("email", graph.email);
            return userData;
        }
        protected override IDictionary<string, string> GetUserData(string accessToken)
        {
            AzureAdUserData graph;
            var request = WebRequest.Create($"{_graphApiEndpoint}/me?api-version={_graphApiVersion}");
            request.Headers.Add(HttpRequestHeader.Authorization.ToString(), $"Bearer {accessToken}");
            using (var response = request.GetResponse())
            {
                using (var responseStream = response.GetResponseStream())
                {
                    graph = JsonHelper.Deserialize<AzureAdUserData>(responseStream);
                }
            }

            var userData = new Dictionary<string, string>();
            userData.AddItemIfNotEmpty("id", graph.userPrincipalName);
            userData.AddItemIfNotEmpty("objectId", graph.objectId);
            userData.AddItemIfNotEmpty("username", graph.userPrincipalName);
            userData.AddItemIfNotEmpty("name", graph.displayName);
            return userData;
        }
        protected override Dictionary<string, string> GetExtraData(IAuthenticationResponse response)
        {
            var fetchResponse = response.GetExtension<FetchResponse>();
            if (fetchResponse != null)
            {
                var extraData = new Dictionary<string, string>();
                extraData.AddItemIfNotEmpty(ClaimTypes.IsPersistent, fetchResponse.GetAttributeValue(ClaimTypes.IsPersistent));

                return extraData;
            }
            return null;
        }
        protected override IDictionary<string, string> GetUserData(string accessToken)
        {
            UriBuilder builder = new UriBuilder(ResourceEndpoint);
            builder.AppendQueryArgument("schema", Scope);

            var request = WebRequest.Create(builder.ToString());
            request.Headers["Authorization"] = string.Concat("Bearer ", accessToken);

            OpenIdConnectGraph data;
            using (WebResponse response = request.GetResponse())
            using (StreamReader reader = new StreamReader(response.GetResponseStream()))
            {
                data = JsonConvert.DeserializeObject<OpenIdConnectGraph>(reader.ReadToEnd());
            }

            Dictionary<string, string> dictionary = new Dictionary<string, string>();
            dictionary.AddItemIfNotEmpty("fullname", data.Name);
            dictionary.AddItemIfNotEmpty("id", data.Email);
            dictionary.AddItemIfNotEmpty("email", data.Email);
            dictionary.AddItemIfNotEmpty("firstname", data.Firstname);
            dictionary.AddItemIfNotEmpty("lastname", data.Lastname);
            return dictionary;
        }
Example #11
0
		/// <summary>
		/// The get user data.
		/// </summary>
		/// <param name="accessToken">
		/// The access token.
		/// </param>
		/// <returns>A dictionary of profile data.</returns>
		protected override IDictionary<string, string> GetUserData(string accessToken) {
			FacebookGraphData graphData;
			var request =
				WebRequest.Create(
					"https://graph.facebook.com/me?access_token=" + MessagingUtilities.EscapeUriDataStringRfc3986(accessToken));
			using (var response = request.GetResponse()) {
				using (var responseStream = response.GetResponseStream()) {
					graphData = JsonHelper.Deserialize<FacebookGraphData>(responseStream);
				}
			}

			// this dictionary must contains 
			var userData = new Dictionary<string, string>();
			userData.AddItemIfNotEmpty("id", graphData.Id);
			userData.AddItemIfNotEmpty("username", graphData.Email);
			userData.AddItemIfNotEmpty("name", graphData.Name);
			userData.AddItemIfNotEmpty("link", graphData.Link == null ? null : graphData.Link.AbsoluteUri);
			userData.AddItemIfNotEmpty("gender", graphData.Gender);
			userData.AddItemIfNotEmpty("birthday", graphData.Birthday);
			return userData;
		}
Example #12
0
        /// <summary>
        /// The get user data.
        /// </summary>
        /// <param name="accessToken">
        /// The access token.
        /// </param>
        /// <returns>A dictionary of profile data.</returns>
        protected override IDictionary<string, string> GetUserData(string accessToken)
        {
            var graphData = new FacebookGraphData();
            var request =
                WebRequest.Create(
                    "https://graph.facebook.com/me?access_token=" + accessToken);

            using (var response = request.GetResponse())
            {
                using (var responseStream = response.GetResponseStream())
                {
                    var serializer = new DataContractJsonSerializer(typeof (FacebookGraphData));

                    if (responseStream != null)
                        graphData = (FacebookGraphData) serializer.ReadObject(responseStream);
                }
            }

            // this dictionary must contains
            var userData = new Dictionary<string, string>();
            userData.AddItemIfNotEmpty("id", graphData.Id);
            userData.AddItemIfNotEmpty("username", graphData.Email);
            userData.AddItemIfNotEmpty("name", graphData.Name);
            userData.AddItemIfNotEmpty("link", graphData.Link == null ? null : graphData.Link.AbsoluteUri);
            userData.AddItemIfNotEmpty("gender", graphData.Gender);
            userData.AddItemIfNotEmpty("birthday", graphData.Birthday);
            userData.AddItemIfNotEmpty("photo", String.Format("http://graph.facebook.com/{0}/picture?width=156&height=156", graphData.Id));
            return userData;
        }
Example #13
0
        /// <summary>
        /// The get user data.
        /// </summary>
        /// <param name="accessToken">
        /// The access token.
        /// </param>
        /// <returns>A dictionary of profile data.</returns>
        protected override IDictionary<string, string> GetUserData(string accessToken)
        {
            var builder = new UriBuilder(GetUsersEndpoint);
            builder.AppendQueryArgs(
                new Dictionary<string, string> {
					{ "uid", _accessTokenResponse.user_id.ToString(CultureInfo.InvariantCulture) },
					{ "access_token", _accessTokenResponse.access_token }
				});


            using (var client = new WebClient { Encoding = Encoding.UTF8 })
            {
                string data = client.DownloadString(builder.Uri);
                if (string.IsNullOrEmpty(data))
                {
                    return null;
                }
                var response = JsonConvert.DeserializeObject<VkApiResponse>(data);
                if (response != null && response.response.Length == 1)
                {
                    var userData = new Dictionary<string, string>();
                    userData.AddItemIfNotEmpty("id", response.response[0].uid);
                    userData.AddItemIfNotEmpty("name", response.response[0].first_name + " " + response.response[0].last_name);

                    return userData;
                }
            }
            return new Dictionary<string, string>();
        }
Example #14
0
        protected override IDictionary<string, string> GetUserData(string accessToken)
        {
            if (accessToken == null) throw new ArgumentNullException("accessToken");
            var data = HttpContext.Current.Session["OdnoklassnikiOAuthProvider.Token"] as OdnoklassnikiTokenResponse;
            if (data == null || data.AccessToken != accessToken)
                return null;
            var res = new Dictionary<string, string>();
            var builder = new UriBuilder("http://api.odnoklassniki.ru/fb.do");
            //$curl = curl_init('http://api.odnoklassniki.ru/fb.do?access_token=' . $auth['access_token'] .
            //'&application_key=' . $AUTH['application_key'] . '&method=users.getCurrentUser&sig=' .
            //md5('application_key=' . $AUTH['application_key'] . 'method=users.getCurrentUser' . md5($auth['access_token'] . $AUTH['client_secret'])));

            var sign = String.Format("{0}{1}", accessToken, AppSecret).CalculateMd5Hash().ToLower();
            sign = String.Format("application_key={0}method=users.getCurrentUser{1}", AppPublic, sign).CalculateMd5Hash().ToLower();
            var args = new Dictionary<string, string>
                {
                    {"method", "users.getCurrentUser"},
                    {"access_token", accessToken},
                    {"application_key", AppPublic},
                    {"sig", sign},
                };
            builder.AppendQueryArgs(args);
            using (var client = new WebClient())
            {
                using (var stream = client.OpenRead(builder.Uri))
                {
                    var serializer = new DataContractJsonSerializer(typeof (OdnoklassnikiDataItem));
                    if (stream != null)
                    {
                        var info = (OdnoklassnikiDataItem) serializer.ReadObject(stream);
                        if (info != null)
                        {
                            var item = info;
                            res.AddItemIfNotEmpty("id", item.UserId);
                            res.AddItemIfNotEmpty("username", item.UserId);
                            res.AddItemIfNotEmpty("name",
                                                  item.Name ??
                                                  (((item.FirstName ?? "") + " " + (item.LastName ?? "")).Trim()));
                            res.AddItemIfNotEmpty("birthday", item.Birthdate);
                            res.AddItemIfNotEmpty("gender", item.Sex);
                            res.AddItemIfNotEmpty("link", String.Format("http://odnoklassniki.ru/profile/{0}", item.UserId));
                            res.AddItemIfNotEmpty("photo", item.Photo ?? item.Photo2);
                        }
                    }
                }
            }
            return res;
        }
        /// <summary>
        /// The get user data.
        /// </summary>
        /// <param name="accessToken">
        /// The access token.
        /// </param>
        /// <returns>A dictionary of profile data.</returns>
        protected override IDictionary<string, string> GetUserData(string accessToken)
        {
            // Source documents
            // http://api.mail.ru/docs/guides/restapi/
            // http://api.mail.ru/docs/reference/rest/users.getInfo/

            var uriBuilder = new UriBuilder(UserInfoServiceEndpoint);

            var args = new Dictionary<string, string>();

            args.Add("app_id", this.appId);
            args.Add("method", "users.getInfo");
            args.Add("secure", "1");
            args.Add("session_key", accessToken);

            // workaround for current design, oauth_token is always present in URL, so we need emulate it for correct request signing 
            args.Add("oauth_token", accessToken);

            // sign=hex_md5('app_id={client_id}method=users.getInfosecure=1session_key={access_token}{secret_key}')
            var signature = string.Concat(args.OrderBy(x => x.Key).Select(x => string.Format("{0}={1}", x.Key, x.Value)).ToList());
            signature = (signature + this.appSecret).GetMd5Hash();

            // removing fake param to prevent dups
            args.Remove("oauth_token");

            args.Add("sig", signature);

            uriBuilder.AppendQueryArgs(args);

            using (var webClient = new WebClient())
            {
                webClient.Encoding = Encoding.UTF8;

                var text = webClient.DownloadString(uriBuilder.Uri);
                if (string.IsNullOrEmpty(text))
                    return null;

                var data = JObject.Parse(text);

                var user = data[0];

                var dictionary = new Dictionary<string, string>();
                dictionary.AddItemIfNotEmpty("id", user["uid"].Value<string>());
                dictionary.AddItemIfNotEmpty("firstName", user["first_name"].Value<string>());
                dictionary.AddItemIfNotEmpty("lastName", user["last_name"].Value<string>());
                dictionary.AddItemIfNotEmpty("email", user["email"].Value<string>());
                return dictionary;
            }
        }
		/// <summary>
		/// Given the access token, gets the logged-in user's data. The returned dictionary must include two keys 'id', and 'username'.
		/// </summary>
		/// <param name="accessToken">
		/// The access token of the current user. 
		/// </param>
		/// <returns>
		/// A dictionary contains key-value pairs of user data 
		/// </returns>
		protected override IDictionary<string, string> GetUserData(string accessToken) {
			WindowsLiveUserData graph;
			var request =
				WebRequest.Create(
					"https://apis.live.net/v5.0/me?access_token=" + MessagingUtilities.EscapeUriDataStringRfc3986(accessToken));
			using (var response = request.GetResponse()) {
				using (var responseStream = response.GetResponseStream()) {
					graph = JsonHelper.Deserialize<WindowsLiveUserData>(responseStream);
				}
			}

			var userData = new Dictionary<string, string>();
			userData.AddItemIfNotEmpty("id", graph.Id);
			userData.AddItemIfNotEmpty("username", graph.Name);
			userData.AddItemIfNotEmpty("name", graph.Name);
			userData.AddItemIfNotEmpty("link", graph.Link == null ? null : graph.Link.AbsoluteUri);
			userData.AddItemIfNotEmpty("gender", graph.Gender);
			userData.AddItemIfNotEmpty("firstname", graph.FirstName);
			userData.AddItemIfNotEmpty("lastname", graph.LastName);
			return userData;
		}
Example #17
0
 protected override IDictionary<string, string> GetUserData(string accessToken)
 {
     if (accessToken == null) throw new ArgumentNullException("accessToken");
     var data = HttpContext.Current.Session["VKontakteOAuthProvider.Token"] as VKontakteTokenResponse;
     if (data == null || data.AccessToken != accessToken)
         return null;
     var res = new Dictionary<string, string>
         {
             {"id", data.UserId.ToString(CultureInfo.InvariantCulture)}
         };
     var builder = new UriBuilder("https://api.vk.com/method/users.get");
     var args = new Dictionary<string, string>
         {
             {"uids", data.UserId.ToString(CultureInfo.InvariantCulture)},
             {"fields", "uid,first_name,last_name,screen_name,nickname,sex,bdate,photo_big,photo,contacts"},
             {"access_token", accessToken}
         };
     builder.AppendQueryArgs(args);
     using (var client = new WebClient()) {
         using (var stream = client.OpenRead(builder.Uri)) {
             var serializer = new DataContractJsonSerializer(typeof(VKontakteDataResponse));
             if (stream != null)
             {
                 var info = (VKontakteDataResponse)serializer.ReadObject(stream);
                 if (info.Items != null && info.Items.Any()) {
                     var item = info.Items[0];
                     res.AddItemIfNotEmpty("username", item.Username);
                     res.AddItemIfNotEmpty("name", (((item.FirstName ?? "") + " " + (item.LastName ?? "")).Trim()));
                     res.AddItemIfNotEmpty("birthday", item.Birthdate);
                     res.AddItemIfNotEmpty("gender", item.Sex);
                     res.AddItemIfNotEmpty("photo", item.PhotoBig ?? item.Photo);
                     res.AddItemIfNotEmpty("phone", item.PhoneMobile ?? item.PhoneHome ?? item.Phone);
                 }
             }
         }
     }
     return res;
 }
        /// <summary>
        /// The get user data.
        /// </summary>
        /// <param name="accessToken">
        /// The access token.
        /// </param>
        /// <returns>A dictionary of profile data.</returns>
        protected override IDictionary<string, string> GetUserData(string accessToken)
        {
            var uriBuilder = new UriBuilder(UserInfoServiceEndpoint);

            var args = new Dictionary<string, string>();

            args.Add("oauth_token", accessToken);
            args.Add("v", DateTime.Now.ToString("yyyyMMdd"));

            uriBuilder.AppendQueryArgs(args);

            using (var webClient = new WebClient())
            {
                webClient.Encoding = Encoding.UTF8;

                var text = webClient.DownloadString(uriBuilder.Uri);
                if (string.IsNullOrEmpty(text))
                    return null;

                var data = JObject.Parse(text);

                var user = data["response"]["user"];

                var dictionary = new Dictionary<string, string>();
                dictionary.AddItemIfNotEmpty("id", user["id"].Value<string>());
                dictionary.AddItemIfNotEmpty("firstName", user["firstName"].Value<string>());
                dictionary.AddItemIfNotEmpty("lastName", user["lastName"].Value<string>());
                dictionary.AddItemIfNotEmpty("email", user["contact"]["email"].Value<string>());
                return dictionary;
            }
        }
        protected override IDictionary<string, string> GetUserData(string accessToken)
        {
            MicrosoftClientUserDataWithEmail graph;
            WebRequest request = WebRequest.Create("https://apis.live.net/v5.0/me?access_token=" + UriExtensions.EscapeUriDataStringRfc3986(accessToken));
            using (WebResponse response = request.GetResponse()) {
                using (Stream responseStream = response.GetResponseStream()) {
                    string json = new StreamReader(responseStream).ReadToEnd();
                    graph = JsonConvert.DeserializeObject<MicrosoftClientUserDataWithEmail>(json);
                }
            }

            var userData = new Dictionary<string, string>();
            userData.AddItemIfNotEmpty("id", graph.Id);
            userData.AddItemIfNotEmpty("username", graph.Name);
            userData.AddItemIfNotEmpty("name", graph.Name);
            userData.AddItemIfNotEmpty("link", graph.Link == null ? null : graph.Link.AbsoluteUri);
            userData.AddItemIfNotEmpty("gender", graph.Gender);
            userData.AddItemIfNotEmpty("firstname", graph.FirstName);
            userData.AddItemIfNotEmpty("lastname", graph.LastName);
            userData.AddItemIfNotEmpty("preferred_email", graph.Emails.Preferred);
            userData.AddItemIfNotEmpty("account_email", graph.Emails.Account);
            userData.AddItemIfNotEmpty("personal_email", graph.Emails.Personal);
            userData.AddItemIfNotEmpty("business_email", graph.Emails.Business);
            return userData;
        }
Example #20
0
        /// <summary>
        /// Given the access token, gets the logged-in user's data. The returned dictionary must include two keys 'id', and 'username'.
        /// </summary>
        /// <param name="accessToken">
        /// The access token of the current user. 
        /// </param>
        /// <returns>
        /// A dictionary contains key-value pairs of user data 
        /// </returns>
        protected override IDictionary<string, string> GetUserData(string accessToken)
        {
            SalesForceSignIn.SalesforceClientUserData graph;
            var request = WebRequest.Create(idUrl);
            request.Headers.Add("Authorization", "Bearer " + accessToken);
            using (var response = request.GetResponse())
            {
                using (var responseStream = response.GetResponseStream())
                {
                    graph = JsonHelper.Deserialize<SalesForceSignIn.SalesforceClientUserData>(responseStream);
                }
            }

            var userData = new Dictionary<string, string>();
            userData.AddItemIfNotEmpty("id", graph.Id);
            userData.AddItemIfNotEmpty("username", graph.Username);
            userData.AddItemIfNotEmpty("firstname", graph.FirstName);
            userData.AddItemIfNotEmpty("lastname", graph.LastName);
            return userData;
        }
        /// <summary>
        /// The get user data.
        /// </summary>
        /// <param name="accessToken">
        /// The access token.
        /// </param>
        /// <returns>A dictionary of profile data.</returns>
        protected override IDictionary<string, string> GetUserData(string accessToken)
        {
            var uriBuilder = new UriBuilder(UserInfoServiceEndpoint.Replace("{{user-id}}", currentUserId));

            var args = new Dictionary<string, string>();

            args.Add("access_token", accessToken);

            uriBuilder.AppendQueryArgs(args);

            using (var webClient = new WebClient())
            {
                webClient.Encoding = Encoding.UTF8;

                var text = webClient.DownloadString(uriBuilder.Uri);
                if (string.IsNullOrEmpty(text))
                    return null;

                var data = JObject.Parse(text);

                var user = data["data"];

                var names = user["full_name"].Value<string>().Split(' ');

                var dictionary = new Dictionary<string, string>();
                dictionary.AddItemIfNotEmpty("id", user["id"].Value<string>());
                dictionary.AddItemIfNotEmpty("firstName", names.Any() ? names.First() : data["username"].Value<string>());
                dictionary.AddItemIfNotEmpty("lastName", names.Count() > 1 ? names.Last() : string.Empty);
                return dictionary;
            }
        }
        /// <summary>
        /// The get user data.
        /// </summary>
        /// <param name="accessToken">
        /// The access token.
        /// </param>
        /// <returns>A dictionary of profile data.</returns>
        protected override IDictionary<string, string> GetUserData(string accessToken)
        {
            // Source document 
            // http://api.yandex.com/oauth/doc/dg/yandex-oauth-dg.pdf

            var uriBuilder = new UriBuilder(UserInfoServiceEndpoint);

            var args = new Dictionary<string, string>();

            args.Add("oauth_token", accessToken);

            uriBuilder.AppendQueryArgs(args);

            using (var webClient = new WebClient())
            {
                webClient.Encoding = Encoding.UTF8;

                var text = webClient.DownloadString(uriBuilder.Uri);
                if (string.IsNullOrEmpty(text))
                    return null;

                var data = JObject.Parse(text);

                var names = data["real_name"].Value<string>().Split(' ');

                var dictionary = new Dictionary<string, string>();
                dictionary.AddItemIfNotEmpty("id", data["id"].Value<string>());
                dictionary.AddItemIfNotEmpty("firstName", names.Any() ? names.First() : data["display_name"].Value<string>());
                dictionary.AddItemIfNotEmpty("lastName", names.Count() > 1 ? names.Last() : string.Empty);
                dictionary.AddItemIfNotEmpty("email", data["default_email"].Value<string>());
                return dictionary;
            }
        }
        /// <summary>
        /// The get user data.
        /// </summary>
        /// <param name="accessToken">
        /// The access token.
        /// </param>
        /// <returns>A dictionary of profile data.</returns>
        protected override IDictionary<string, string> GetUserData(string accessToken)
        {
            var uriBuilder = new UriBuilder(UserInfoServiceEndpoint);

            var args = new Dictionary<string, string>();

            args.Add("access_token", accessToken);

            uriBuilder.AppendQueryArgs(args);

            using (var webClient = new WebClient())
            {
                webClient.Encoding = Encoding.UTF8;

                var text = webClient.DownloadString(uriBuilder.Uri);
                if (string.IsNullOrEmpty(text))
                    return null;

                var data = JObject.Parse(text);

                var names = (data["name"].Value<string>() ?? string.Empty).Split(' ').ToList();

                var dictionary = new Dictionary<string, string>();
                dictionary.AddItemIfNotEmpty("id", data["id"].Value<string>());
                dictionary.AddItemIfNotEmpty("firstName", names.Count > 0 ? names.First() : data["login"].Value<string>());
                dictionary.AddItemIfNotEmpty("lastName", names.Count > 1 ? names.Last() : string.Empty);
                dictionary.AddItemIfNotEmpty("email", data["email"].Value<string>());
                return dictionary;
            }
        }
        /// <summary>
        /// The get user data.
        /// </summary>
        /// <param name="accessToken">
        /// The access token.
        /// </param>
        /// <returns>A dictionary of profile data.</returns>
        protected override IDictionary<string, string> GetUserData(string accessToken)
        {
            // Source document
            // http://dev.odnoklassniki.ru/wiki/pages/viewpage.action?pageId=12878032

            var uriBuilder = new UriBuilder(UserInfoServiceEndpoint);

            var args = new Dictionary<string, string>();

            args.Add("application_key", this.appPublic);
            args.Add("method", "users.getCurrentUser");

            // Signing.
            // Call API methods using access_token instead of session_key parameter
            // Calculate every request signature parameter sig using a little bit different way described in
            // http://dev.odnoklassniki.ru/wiki/display/ok/Authentication+and+Authorization
            // sig = md5( request_params_composed_string+ md5(access_token + application_secret_key)  )
            // Don't include access_token into request_params_composed_string
            var signature = string.Concat(args.OrderBy(x => x.Key).Select(x => string.Format("{0}={1}", x.Key, x.Value)).ToList());
            signature = (signature + (accessToken + this.appSecret).GetMd5Hash()).GetMd5Hash();

            args.Add("access_token", accessToken);
            args.Add("sig", signature);

            uriBuilder.AppendQueryArgs(args);

            using (var webClient = new WebClient())
            {
                webClient.Encoding = Encoding.UTF8;

                var text = webClient.DownloadString(uriBuilder.Uri);
                if (string.IsNullOrEmpty(text))
                    return null;

                var data = JObject.Parse(text);

                var dictionary = new Dictionary<string, string>();
                dictionary.AddItemIfNotEmpty("id", data["uid"].Value<string>());
                dictionary.AddItemIfNotEmpty("firstName", data["first_name"].Value<string>());
                dictionary.AddItemIfNotEmpty("lastName", data["last_name"].Value<string>());
                return dictionary;
            }
        }
        /// <summary>
        /// The get user data.
        /// </summary>
        /// <param name="accessToken">
        /// The access token.
        /// </param>
        /// <returns>A dictionary of profile data.</returns>
        protected override IDictionary<string, string> GetUserData(string accessToken)
        {
            var uriBuilder = new UriBuilder(UserInfoServiceEndpoint);

            var args = new Dictionary<string, string>();

            args.Add("uids", currentUserId.ToString());
            args.Add("fields", "uid,first_name,last_name,photo");
            args.Add("access_token", accessToken);

            uriBuilder.AppendQueryArgs(args);

            using (var webClient = new WebClient())
            {
                webClient.Encoding = Encoding.UTF8;

                var text = webClient.DownloadString(uriBuilder.Uri);
                if (string.IsNullOrEmpty(text))
                    return null;

                var data = JObject.Parse(text);

                var user = data["response"][0];

                var dictionary = new Dictionary<string, string>();
                dictionary.AddItemIfNotEmpty("id", user["uid"].Value<string>());
                dictionary.AddItemIfNotEmpty("firstName", user["first_name"].Value<string>());
                dictionary.AddItemIfNotEmpty("lastName", user["last_name"].Value<string>());
                return dictionary;
            }
        }