Ejemplo n.º 1
0
        public virtual OAuthRequestToken GetRequestToken(string callback)
        {
            var args = new FunctionArguments
            {
                ConsumerKey    = _consumerKey,
                ConsumerSecret = _consumerSecret
            };

            var request = _requestTokenQuery.Invoke(args);

            if (!callback.IsNullOrBlank())
            {
                request.AddParameter("client_id", _consumerKey);
                request.AddParameter("redirect_uri", callback);
            }

            var response = _oauth.Request(request);

            SetResponse(response);

            ////var query = HttpUtility.ParseQueryString(response.Content);

            var query = JObject.Parse(response.Content);
            var oauth = new OAuthRequestToken
            {
                ////Token = query["oauth_token"] ?? "?",
                ////TokenSecret = query["oauth_token_secret"] ?? "?",
                ////OAuthCallbackConfirmed = Convert.ToBoolean(query["oauth_callback_confirmed"] ?? "false")
            };

            return(oauth);
        }
Ejemplo n.º 2
0
        public virtual OAuthAccessToken GetAccessToken(OAuthRequestToken requestToken, string verifier)
        {
            var args = new FunctionArguments
            {
                ConsumerKey    = _consumerKey,
                ConsumerSecret = _consumerSecret,
                Token          = requestToken.Token,
                TokenSecret    = requestToken.TokenSecret,
                Verifier       = verifier
            };

            // Invokes a delegate.
            var request = _accessTokenQuery.Invoke(args);

            // Gets the server response.
            var response = _oauth.Request(request);

            SetResponse(response);

            // Convert the reserver char to readable text, for instance
            //  ,<,> and &quot.
            var query = HttpUtility.ParseQueryString(response.Content);

            var accessToken = new OAuthAccessToken
            {
                Token       = query["oauth_token"] ?? "?",
                TokenSecret = query["oauth_token_secret"] ?? "?",
                UserId      = query["user_id"].ToInt64(),
                ScreenName  = /*query["screen_name"] ??*/ "?"
            };

            return(accessToken);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Gets the authorization URI base on oauth_token,
 /// then direct user to service provider.
 /// </summary>
 /// <param name="oauth">The oauth.</param>
 /// <returns>The direct uri.</returns>
 public virtual Uri GetAuthorizationUri(OAuthRequestToken oauth)
 {
     return(new Uri("http://api.t.sina.com.cn/oauth/authorize?oauth_token=" + oauth.Token));
 }