示例#1
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)
        {
            OAuthMicrosoftClientData data;

            using (var response = WebRequest.Create(UserDataEndpoint + HttpUtility.UrlEncode(accessToken)).GetResponse())
            {
                using (var stream = response.GetResponseStream())
                {
                    data = OAuthHelpers.Deserialize <OAuthMicrosoftClientData>(stream);
                }
            }

            // Try to select an email address for the user. :S
            string email = data.Emails.Preferred ?? data.Emails.Account ?? data.Emails.Personal ?? data.Emails.Business;

            string birthday;

            try
            {
                birthday = new DateTime(data.BirthYear, data.BirthMonth, data.BirthDay).ToString();
            }
            catch (ArgumentOutOfRangeException)
            {
                birthday = null;
            }

            return(OAuthHelpers.CreateResponse(data.Id, email, data.Name, data.FirstName, data.LastName, data.Gender, data.Link, birthday));
        }
示例#2
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)
        {
            OAuthFacebookClientData data;

            using (var response = WebRequest.Create(UserDataEndpoint + HttpUtility.UrlEncode(accessToken)).GetResponse())
            {
                using (var stream = response.GetResponseStream())
                {
                    data = OAuthHelpers.Deserialize <OAuthFacebookClientData>(stream);
                }
            }

            return(OAuthHelpers.CreateResponse(data.Id, data.Email, data.Name, data.FirstName, data.LastName, data.Gender, data.Link, data.Birthday));
        }
示例#3
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)
        {
            var builder = new UriBuilder(UserDataEndpoint);

            builder.SetQuery(new UriParameter("access_token", accessToken));

            OAuthGoogleClientData data;

            using (var response = WebRequest.Create(builder.Uri).GetResponse())
            {
                using (var stream = response.GetResponseStream())
                {
                    data = OAuthHelpers.Deserialize <OAuthGoogleClientData>(stream);
                }
            }

            return(OAuthHelpers.CreateResponse(data.Id, data.Email, data.Name, data.FirstName, data.LastName, data.Gender, data.Link, data.Birthday));
        }