Exemplo n.º 1
0
        public override string RequestToken(HttpRequestBase request)
        {
            var oauthToken    = request["oauth_token"];
            var oauthVerifier = request["oauth_verifier"];

            if (String.IsNullOrEmpty(oauthToken) || String.IsNullOrEmpty(oauthVerifier))
            {
                return(OAuth2Consts.ACCESS_DENIED);
            }

            string postData = QueryStringBuilder.Build(
                "oauth_consumer_key", _client.ClientId,
                "oauth_nonce", _util.GetNonce(),
                "oauth_signature_method", "HMAC-SHA1",
                "oauth_timestamp", _util.GetTimeStamp(),
                "oauth_token", oauthToken,
                "oauth_verifier", oauthVerifier,
                "oauth_version", "1.0"
                );

            const string accessTokenUrl = "https://api.twitter.com/oauth/access_token";
            var          signature      = _util.GetSha1Signature("POST", accessTokenUrl, postData, _client.ClientSecret);
            var          responseText   = HttpPost(accessTokenUrl, postData + "&oauth_signature=" + Uri.EscapeDataString(signature));

            var twitterAuthResp = new TwitterAuthResponse(responseText);

            _client.Token       = twitterAuthResp.OAuthToken;
            _client.TokenSecret = twitterAuthResp.OAuthTokenSecret;

            return(twitterAuthResp.OAuthToken);
        }
        protected override void beforeEach()
        {
            theHandlers = MockFor <ITwitterResponseHandler>();

            theResponse = new TwitterAuthResponse(123, "test_user", new StubTokenResponse {
                AccessToken = "Test1234"
            });

            Services.Inject <ITwitterProxy>(new StubTwitterProxy(theResponse));

            ClassUnderTest.Execute();
        }
Exemplo n.º 3
0
        public override string BeginAuthentication()
        {
            var qstring = QueryStringBuilder.Build(
                // Twitter relies on Callback URL setting on http://apps.twitter.com/
                // If you set client callback here it'll return 401
                //                "oauth_callback", _client.CallBackUrl,
                "oauth_consumer_key", _client.ClientId,
                "oauth_nonce", _util.GetNonce(),
                "oauth_signature_method", "HMAC-SHA1",
                "oauth_timestamp", _util.GetTimeStamp(),
                "oauth_version", "1.0"
                );

            const string requestTokenUrl = "https://api.twitter.com/oauth/request_token";
            var signature = _util.GetSha1Signature("POST", requestTokenUrl, qstring, _client.ClientSecret);
            var responseText = HttpPost(requestTokenUrl, qstring + "&oauth_signature=" + Uri.EscapeDataString(signature));

            var twitterAuthResp = new TwitterAuthResponse(responseText);

            const string authenticateUrl = "https://api.twitter.com/oauth/authenticate";
            var oauthUrl = authenticateUrl + "?oauth_token=" + twitterAuthResp.OAuthToken;

            return oauthUrl;
        }
Exemplo n.º 4
0
        public override string BeginAuthentication()
        {
            var qstring = QueryStringBuilder.Build(
                // Twitter relies on Callback URL setting on http://apps.twitter.com/
                // If you set client callback here it'll return 401
                //                "oauth_callback", _client.CallBackUrl,
                "oauth_consumer_key", _client.ClientId,
                "oauth_nonce", _util.GetNonce(),
                "oauth_signature_method", "HMAC-SHA1",
                "oauth_timestamp", _util.GetTimeStamp(),
                "oauth_version", "1.0"
                );

            const string requestTokenUrl = "https://api.twitter.com/oauth/request_token";
            var          signature       = _util.GetSha1Signature("POST", requestTokenUrl, qstring, _client.ClientSecret);
            var          responseText    = HttpPost(requestTokenUrl, qstring + "&oauth_signature=" + Uri.EscapeDataString(signature));

            var twitterAuthResp = new TwitterAuthResponse(responseText);

            const string authenticateUrl = "https://api.twitter.com/oauth/authenticate";
            var          oauthUrl        = authenticateUrl + "?oauth_token=" + twitterAuthResp.OAuthToken;

            return(oauthUrl);
        }
Exemplo n.º 5
0
        private static void _getBearerAuthToken()
        {
            string encodedCreds = _encodeCredentials();

            HttpRequestMessage req = new HttpRequestMessage(HttpMethod.Post, TwitterEndpoints.OA_TOKEN);

            req.Headers.Clear();
            req.Headers.ExpectContinue = false;
            req.Headers.Add("User-Agent", "Deletus-Tweetus");
            req.Headers.Add("Authorization", $"Basic {encodedCreds}");
            req.Content = new StringContent("grant_type=client_credentials", Encoding.UTF8, "application/x-www-form-urlencoded");

            string response = "";

            HttpContent content = client.SendAsync(req).Result.Content;

            response = content.ReadAsStringAsync().Result;

            //  JSON string into an object so we can get the bearer_token
            TwitterAuthResponse x = JsonConvert.DeserializeObject <TwitterAuthResponse>(response);

            TwitterApiBearerToken = x.access_token;
            cLog("TwitterApiBearerToken =  " + TwitterApiBearerToken + "\n");
        }
 public StubTwitterProxy(TwitterAuthResponse response)
 {
     _response = response;
 }
Exemplo n.º 7
0
 public StubTwitterProxy(TwitterAuthResponse response)
 {
     _response = response;
 }
Exemplo n.º 8
0
        public override string RequestToken(HttpRequestBase request)
        {
            var oauthToken = request["oauth_token"];
            var oauthVerifier = request["oauth_verifier"];

            if (String.IsNullOrEmpty(oauthToken) || String.IsNullOrEmpty(oauthVerifier))
                return OAuth2Consts.ACCESS_DENIED;

            string postData = QueryStringBuilder.Build(
                "oauth_consumer_key", _client.ClientId,
                "oauth_nonce", _util.GetNonce(),
                "oauth_signature_method", "HMAC-SHA1",
                "oauth_timestamp", _util.GetTimeStamp(),
                "oauth_token", oauthToken,
                "oauth_verifier", oauthVerifier,
                "oauth_version", "1.0"
                );

            const string accessTokenUrl = "https://api.twitter.com/oauth/access_token";
            var signature = _util.GetSha1Signature("POST", accessTokenUrl, postData, _client.ClientSecret);
            var responseText = HttpPost(accessTokenUrl, postData + "&oauth_signature=" + Uri.EscapeDataString(signature));

            var twitterAuthResp = new TwitterAuthResponse(responseText);

            _client.Token = twitterAuthResp.OAuthToken;
            _client.TokenSecret = twitterAuthResp.OAuthTokenSecret;

            return twitterAuthResp.OAuthToken;
        }