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); }
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); }