コード例 #1
0
        /// <summary>
        /// Obtains an access token given an authorization code and callback URL.
        /// </summary>
        /// <param name="returnUrl">
        /// The return url.
        /// </param>
        /// <param name="authorizationCode">
        /// The authorization code.
        /// </param>
        /// <returns>
        /// The access token.
        /// </returns>
        protected override string QueryAccessToken(Uri returnUrl, string authorizationCode)
        {
            var builder = new UriBuilder(TokenEndpoint);

            builder.AppendQueryArgument("client_id", _appId);
            builder.AppendQueryArgument("redirect_uri", returnUrl.AbsoluteUri);
            builder.AppendQueryArgument("client_secret", _appSecret);
            builder.AppendQueryArgument("code", authorizationCode);

            using (var client = new ExtendedWebClient(_userAgent))
            {
                var data = client.DownloadString(builder.Uri);

                if (string.IsNullOrEmpty(data))
                {
                    return null;
                }

                var parsedQueryString = HttpUtility.ParseQueryString(data);

                return parsedQueryString["access_token"];
            }
        }
コード例 #2
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)
 {
     using (var client = new ExtendedWebClient(_userAgent))
     {
         var data = client.DownloadString(UserEndpoint + "?access_token=" + accessToken);
         return JsonConvert.DeserializeObject<Dictionary<string, string>>(data);
     }
 }