コード例 #1
0
        // geturl
        public string GetRedirectUserUrl(RequestTokenResponse requestToken)
        {
            string redirectUrl
                = String.Format("{0}?{1}={2}", AuthenticateUrl, OAuthTokenParameter, requestToken.OAuthRequestToken);

            return(redirectUrl);
        }
コード例 #2
0
        public async Task <AccessTokenResponse> GetAccessToken(
            RequestTokenResponse requestToken,
            RedirectToAuthResponse redirectToAuth)
        {
            SortedDictionary <string, string> requestParams = new SortedDictionary <string, string>();

            requestParams.Add(OAuthVerifierParameter, redirectToAuth.OAuthVerifier);

            var handler  = new AuthHeaderFilter(this.consumerInfo, requestToken, AccessTokenUrl, requestParams);
            var response = await PostRequest(AccessTokenUrl, requestParams, handler);

            // result:
            // oauth_token=15244042-e0MDgWWgvAsJDVGTrwTbjKJYUOsnUdhNpqccnhBX8&oauth_token_secret=atrv7CXDUJymKxwVyanAVOTAXz0VyDtAx2aXNo9VVfq4i&user_id=15244042&screen_name=kumar0001
            MatchCollection mc = Regex.Matches(response,
                                               @"^oauth_token=(?<token>[^&]+?)&oauth_token_secret=(?<secret>[^&]+?)&user_id=(?<userid>[^&]+?)&screen_name=(?<screenname>.+?)$",
                                               RegexOptions.IgnoreCase | RegexOptions.Singleline);

            if (mc.Count == 1)
            {
                Match m = mc[0];

                return(new AccessTokenResponse()
                {
                    OAuthAccessToken = m.Groups["token"].Value,
                    OAuthAccessTokenSecret = m.Groups["secret"].Value,
                    UserId = m.Groups["userid"].Value,
                    ScreenName = m.Groups["screenname"].Value,
                });
            }
            else
            {
                throw new TwitterOAuthException(String.Format("invalid response: {0}", response));
            }
        }
コード例 #3
0
        // https://dev.twitter.com/docs/api/1/post/oauth/request_token
        public async Task <RequestTokenResponse> GetRequestToken()
        {
            SortedDictionary <string, string> requestParams = new SortedDictionary <string, string>();
            var    handler  = new AuthHeaderFilter(this.consumerInfo, RequestTokenUrl, requestParams);
            string response = await PostRequest(RequestTokenUrl, requestParams, handler);

            // result:
            // oauth_token=UC9NrLRmLge4dBFExQOQ4UGuv6ytvSfpdpgfkoTaBU&oauth_token_secret=TmlhJukIcjPbIsLNRw4vQUFVYjot5jaXABFHiR18&oauth_callback_confirmed=true
            MatchCollection mc = Regex.Matches(response,
                                               @"^oauth_token=(?<token>[^&]+?)&oauth_token_secret=(?<secret>[^&]+?)&oauth_callback_confirmed=(?<confirmed>.+?)$",
                                               RegexOptions.IgnoreCase | RegexOptions.Singleline);

            RequestTokenResponse result;

            if (mc.Count == 1)
            {
                Match m                  = mc[0];
                var   requestToken       = m.Groups["token"].Value;
                var   requestTokenSecret = m.Groups["secret"].Value;
                var   confirmed          = m.Groups["confirmed"].Value;

                result = new RequestTokenResponse()
                {
                    OAuthRequestToken       = requestToken,
                    OAuthRequestTokenSecret = requestTokenSecret,
                    Confirmed = Boolean.Parse(confirmed),
                };
            }
            else
            {
                throw new TwitterOAuthException(String.Format("invalid response: {0}", response));
            }

            return(result);
        }
コード例 #4
0
        //public AuthHeaderFilter(
        //    ConsumerInfo consumerInfo,
        //    string requestUrl,
        //    SortedDictionary<string, string> requestParameters,
        //    HttpMessageHandler handler)
        //    : this(consumerInfo, null, null, requestUrl, requestParameters, handler)
        //{
        //}

        public AuthHeaderFilter(
            ConsumerInfo consumerInfo,
            RequestTokenResponse requestToken,
            string requestUrl,
            SortedDictionary <string, string> requestParameters)
            : this(consumerInfo, requestToken, null, requestUrl, requestParameters, new HttpClientHandler())
        {
        }
コード例 #5
0
        //public AuthHeaderFilter(
        //    ConsumerInfo consumerInfo,
        //    AccessTokenResponse accessToken,
        //    string requestUrl,
        //    SortedDictionary<string, string> requestParameters,
        //    HttpMessageHandler handler)
        //    : this(consumerInfo, null, accessToken, requestUrl, requestParameters, handler)
        //{
        //}

        private AuthHeaderFilter(
            ConsumerInfo consumerInfo,
            RequestTokenResponse requestToken,
            AccessTokenResponse accessToken,
            string requestUrl,
            SortedDictionary <string, string> requestParameters,
            HttpMessageHandler handler)
            : base(handler)
        {
            this.consumerInfo      = consumerInfo;
            this.requestToken      = requestToken;
            this.accessToken       = accessToken;
            this.requestUrl        = requestUrl;
            this.requestParameters = requestParameters;
        }