Exemplo n.º 1
0
        public static OAuthCredentials PerformOAuth(string consumerKey, string consumerSecret)
        {
            OAuthConfig oauthConfig = new OAuthConfig("console");
              oauthConfig.OauthVersion = "1.0";
              oauthConfig.OauthSignatureMethod = "HMAC-SHA1";

              oauthConfig.ConsumerKey = consumerKey;
              oauthConfig.ConsumerSecret = consumerSecret;

              oauthConfig.RequestTokenUrl = "https://api.twitter.com/oauth/request_token";
              oauthConfig.AccessTokenUrl = "https://api.twitter.com/oauth/access_token";
              oauthConfig.UserAuthorizationUrl = "https://api.twitter.com/oauth/authorize";

              OAuthConsumer oauthConsumer = new OAuthConsumer(oauthConfig, "console");
              oauthConsumer.getRequestToken();

              VerificationInput input = new VerificationInput();
              input.ShowDialog();
              string code = input.GetCode();
              oauthConsumer.getAccessToken(code);
              OAuthCredentials rv = new OAuthCredentials();
              rv.Token = oauthConfig.OauthToken;
              rv.Secret = oauthConfig.OauthTokenSecret;
              return rv;
        }
Exemplo n.º 2
0
        public static void Tweet(OAuthConsumer consumer, string text)
        {
            List<QueryParameter> post = new List<QueryParameter>();
              post.Add(new QueryParameter("status", text));

              consumer.request("http://api.twitter.com/1/statuses/update.json", "POST", post, "PLAIN");
        }
Exemplo n.º 3
0
        static void Main( string[] args )
        {
            try {
                System.Net.ServicePointManager.Expect100Continue = false;

                // リクエストトークンを取得
                OAuthProvider provider = new OAuthProvider( APIKey.AccessToken, APIKey.Authorize, APIKey.ReqestToken );
                OAuthConsumer consumer = new OAuthConsumer( OAuth.APIKey.ConsumerKey, OAuth.APIKey.ConsumerSecret );
                string authorizeURL = provider.RetrieveRequestToken( ref consumer );

                //ブラウザからPIN確認
                System.Diagnostics.Process.Start( authorizeURL );
                Console.Write( "PIN:" );
                string pin = Console.ReadLine();

                // アクセストークンを取得
                provider.RetrieveAccessToken( ref consumer, pin );

                Console.WriteLine( "public const string Token = \"" + consumer.Token + "\";" );
                Console.WriteLine( "public const string TokenSecret = \"" + consumer.TokenSecret + "\";" );

                //デスクトップ\oauth_token.txtに保存
                File.WriteAllText( Environment.GetFolderPath( Environment.SpecialFolder.Desktop ) + @"\cacoo_oauth_token.txt",
                    consumer.Token + ", " + consumer.TokenSecret );
            }
            catch ( Exception ex ) {
                Console.WriteLine( ex.Message );
            }
            finally {
                Console.Write( "Press enter : " );
                Console.ReadLine();
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// With this test, the application will request an oauth_access token for the current user. The user will have to authorize the app (this code sample) to access his twitter account.
        /// A combination of keys will be generated for him : an oauth access token.
        /// </summary>
        public void test_twitterOauthClient()
        {
            // Create an OAuth config
            OAuthConfig oauthConfig = new OAuthConfig("console");
            oauthConfig.SiteUrl = "http://www.worldgoneweb.com";
            oauthConfig.OauthVersion = "1.0";
            oauthConfig.OauthSignatureMethod = "HMAC-SHA1";
            oauthConfig.ConsumerKey = TwitterOAuthTest._consumerKey;
            oauthConfig.ConsumerSecret = TwitterOAuthTest._consumerSecret;
            oauthConfig.RequestTokenUrl = "https://api.twitter.com/oauth/request_token";
            oauthConfig.AccessTokenUrl = "https://api.twitter.com/oauth/access_token";
            oauthConfig.UserAuthorizationUrl = "https://api.twitter.com/oauth/authorize";

            // Create an OAuth consumer
            OAuthConsumer oauthConsumer = new OAuthConsumer(oauthConfig, "console");

            // Request Token
            oauthConsumer.getRequestToken();

            // Enter the Pin Code
            Console.WriteLine("Enter the pin code:");
            string pincode = Console.ReadLine();

            // Request Access Token
            oauthConsumer.getAccessToken(pincode);

            // Make an API Call (call the home_timeline status) and debug the response
            string response = (string)oauthConsumer.request("http://api.twitter.com/1/statuses/home_timeline.xml", "GET", null, "PLAIN");
            Console.WriteLine(response);
        }
Exemplo n.º 5
0
        public virtual void loginTwitter(object sender, EventArgs args)
        {
            // Change the button text
            buttonLogin.Text = "Complete authorization with Twitter";

            // Create an OAuth config
            OAuthConfig oauthConfig = new OAuthConfig("console");
            oauthConfig.SiteUrl = "http://www.worldgoneweb.com";
            oauthConfig.OauthVersion = "1.0";
            oauthConfig.OauthSignatureMethod = "HMAC-SHA1";
            oauthConfig.ConsumerKey = ConfigurationManager.AppSettings.Get("consumerKey");
            oauthConfig.ConsumerSecret = ConfigurationManager.AppSettings.Get("consumerSecret");
            oauthConfig.RequestTokenUrl = "https://api.twitter.com/oauth/request_token";
            oauthConfig.AccessTokenUrl = "https://api.twitter.com/oauth/access_token";
            oauthConfig.UserAuthorizationUrl = "https://api.twitter.com/oauth/authorize";

            // Create an OAuth consumer
            OAuthConsumer oauthConsumer = new OAuthConsumer(oauthConfig, "console");

            // Request Token
            oauthConsumer.getRequestToken();

            // After the authorization is completed with Twitter, OAuth will redirect you to the callbackURL declared in your application settings at dev.twitter.com
            // Information about the authenticated user is provided to that page in addition to the access token needed to execute further api calls
        }
Exemplo n.º 6
0
        /// <summary>
        /// アクセストークンの取得
        /// </summary>
        /// <param name="consumer"></param>
        /// <param name="pin"></param>
        public void RetrieveAccessToken( ref OAuthConsumer consumer, string pin )
        {
            // リクエストの作成とレスポンスの取得
            HttpWebRequest webreq = CreateRequest( AccessToken, consumer, POST, pin, RequestFormatAuth );
            string result = GetResponse( webreq );

            // oauth_tokenとoauth_token_secretを取得
            Match match = Regex.Match( result, @"oauth_token=(.*)&oauth_token_secret=(.*)" );
            consumer.SetTokenWithSecret( match.Groups[1].Value, match.Groups[2].Value );
        }
Exemplo n.º 7
0
 public static OAuthConsumer CreateClient(string consumerKey, string consumerSecret, string accessToken, string accessSecret)
 {
     OAuthConfig oauthConfig = new OAuthConfig("console");
       oauthConfig.OauthVersion = "1.0";
       oauthConfig.OauthSignatureMethod = "HMAC-SHA1";
       oauthConfig.ConsumerKey = consumerKey;
       oauthConfig.ConsumerSecret = consumerSecret;
       oauthConfig.OauthToken = accessToken;
       oauthConfig.OauthTokenSecret = accessSecret;
       OAuthConsumer oauthConsumer = new OAuthConsumer(oauthConfig, "console");
       return oauthConsumer;
 }
Exemplo n.º 8
0
        public void PINを取得するためのトークンを取得するためのシグニチャ()
        {
            OAuth.OAuthBase oauth = new TestingOAuth( "1281614602", "8715791" );

            OAuthConsumer consumer = new OAuthConsumer( ConsumerKey, ConsumerSecret );

            Uri uri = new Uri( ReqestToken );
            string signature = oauth.GenerateSignature( uri, consumer, "GET", "" );

            Assert.AreEqual( "FOBRl2mkgAx9tNdQeNIiIxjwhxo=", signature );
            Assert.AreEqual( "oauth_consumer_key=OKWyYVPvnpcBfbdmrJaNWx&oauth_nonce=8715791&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1281614602&oauth_version=1.0",
                oauth.NormalizedRequestParameters );
        }
Exemplo n.º 9
0
        static void Main( string[] args )
        {
            try {
                System.Net.ServicePointManager.Expect100Continue = false;

                OAuthConsumer consumer = new OAuthConsumer( APIKey.ConsumerKey, APIKey.ConsumerSecret );
                consumer.SetTokenWithSecret( APIKey.Token, APIKey.TokenSecret );

                OAuthProvider provider = new OAuthProvider();

                string result = "";

                result = provider.RetrieveRequest( "https://cacoo.com/api/v1/account.xml", consumer );
                Console.WriteLine( "--- アカウント情報取得 ---" );
                Console.WriteLine( result );
                Console.WriteLine( "" );

                result = provider.RetrieveRequest( "https://cacoo.com/api/v1/users/kaorun55.xml", consumer );
                Console.WriteLine( "--- ユーザー情報取得 ---" );
                Console.WriteLine( result );
                Console.WriteLine( "" );

                result = provider.RetrieveRequest( "http://cacoo.com/api/v1/diagrams.xml", consumer );
                Console.WriteLine( "--- 図の一覧取得 ---" );
                Console.WriteLine( result );
                Console.WriteLine( "" );

                result = provider.RetrieveRequest( "http://cacoo.com/api/v1/diagrams/cTedXHIB8T1x1QJS.xml", consumer );
                Console.WriteLine( "--- 図の情報取得 ---" );
                Console.WriteLine( result );
                Console.WriteLine( "" );

                // バイナリの返し方を考える
                //result = provider.RetrieveRequest( "http://cacoo.com/api/v1/diagrams/cTedXHIB8T1x1QJS.png", consumer );
                //Console.WriteLine( "--- 画像取得 ---" );
                //Console.WriteLine( result );
                //Console.WriteLine( "" );
            }
            catch ( Exception ex ) {
                Console.WriteLine( ex.Message );
            }
            finally {
                Console.Write( "Press enter : " );
                Console.ReadLine();
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// With this test, the oauth access token created for the requester of the API key will be used and no authorization process will take place
        /// </summary>
        public void test_twitterOauthSuperClient()
        {
            // Create an OAuth config
            OAuthConfig oauthConfig = new OAuthConfig("console");
            oauthConfig.SiteUrl = "http://www.worldgoneweb.com";
            oauthConfig.OauthVersion = "1.0";
            oauthConfig.OauthSignatureMethod = "HMAC-SHA1";
            oauthConfig.ConsumerKey = TwitterOAuthTest._consumerKey;
            oauthConfig.ConsumerSecret = TwitterOAuthTest._consumerSecret;
            oauthConfig.OauthToken = TwitterOAuthTest._accessToken;
            oauthConfig.OauthTokenSecret = TwitterOAuthTest._accessTokenSecret;

            // Create an OAuth consumer
            OAuthConsumer oauthConsumer = new OAuthConsumer(oauthConfig, "console");

            // Make an API Call (call the home_timeline status) and debug the response
            string response = (string)oauthConsumer.request("http://api.twitter.com/1/statuses/home_timeline.xml", "GET", null, "PLAIN");
            Console.WriteLine(response);
        }
Exemplo n.º 11
0
        private static void getAccessToken( string consumer_key, string consumer_secret )
        {
            System.Net.ServicePointManager.Expect100Continue = false;
            OAuthBase oAuth = new OAuthBase();

            System.Uri uri = new Uri( OAuth.APIKey.ReqestToken );

            //OAuthBace.csを用いてsignature生成
            OAuth.OAuthConsumer consumer = new OAuthConsumer( consumer_key, consumer_secret );
            string signature = oAuth.GenerateSignature( uri, consumer, "GET", "" );

            //oauth_token,oauth_token_secret取得
            HttpWebRequest webreq = (System.Net.HttpWebRequest)WebRequest.Create( OAuth.APIKey.ReqestToken + string.Format( "?{0}&oauth_signature={1}", oAuth.NormalizedRequestParameters, signature ) );
            webreq.Method = "GET";
            HttpWebResponse webres = (HttpWebResponse)webreq.GetResponse();

            string result;
            using ( System.IO.Stream st = webres.GetResponseStream() )
            using ( System.IO.StreamReader sr = new System.IO.StreamReader( st, Encoding.GetEncoding( 932 ) ) ) {
                result = sr.ReadToEnd();
            }

            Console.WriteLine( result );

            //正規表現でoauth_token,oauth_token_secret取得
            Match match = Regex.Match( result, @"oauth_token=(.*?)&oauth_token_secret=(.*?)&oauth_callback.*" );
            string token = match.Groups[1].Value;
            string tokenSecret = match.Groups[2].Value;

            //ブラウザからPIN確認
            string AuthorizeURL = OAuth.APIKey.Authorize + "?" + result;
            System.Diagnostics.Process.Start( AuthorizeURL );
            Console.Write( "PIN:" );
            string PIN = Console.ReadLine();

            //oauth_token,oauth_token_secretを用いて再びsignature生成
            consumer = new OAuthConsumer( consumer_key, consumer_secret );
            consumer.SetTokenWithSecret( token, tokenSecret );
            signature = oAuth.GenerateSignature( uri, consumer, "POST", "" );
            webreq = (System.Net.HttpWebRequest)WebRequest.Create( OAuth.APIKey.AccessToken + string.Format( "?{3}&oauth_signature={0}&oauth_verifier={2}", signature, result, PIN, oAuth.NormalizedRequestParameters ) );

            //oauth_token,oauth_token_secretの取得
            webreq.Method = "POST";
            webres = (System.Net.HttpWebResponse)webreq.GetResponse();

            using ( System.IO.Stream st = webres.GetResponseStream() )
            using ( System.IO.StreamReader sr = new System.IO.StreamReader( st, Encoding.GetEncoding( 932 ) ) ) {
                result = sr.ReadToEnd();
            }

            Console.WriteLine( result );

            //正規表現でoauth_token,oauth_token_secret取得
            match = Regex.Match( result, @"oauth_token=(.*?)&oauth_token_secret=(.*?)&.*" );
            token = match.Groups[1].Value;
            tokenSecret = match.Groups[2].Value;

            Console.WriteLine( "public const string token = \"" + token + "\";" );
            Console.WriteLine( "public const string tokenSecret = \"" + tokenSecret + "\";" );

            //デスクトップ\oauth_token.txtに保存
            File.WriteAllText( Environment.GetFolderPath( Environment.SpecialFolder.Desktop ) + @"\oauth_token.txt", result );
        }
Exemplo n.º 12
0
        public void OnPluginEnable()
        {
            if (twttrAccessToken == null) {
            // we need to auth.
            OAuthCredentials accessToken = TwitterHelper.PerformOAuth(CONSUMER_KEY, CONSUMER_SECRET);
            consoleWrite("^8OAuth Successful. Please copy and paste the following values into the plugin configuration, and reactivate: ");
            consoleWrite("Access Token: " + accessToken.Token);
            consoleWrite("Access Token Secret: " + accessToken.Secret);
            consoleWrite("Please keep the token secret safe. You can unauthorize this application at any time from your Twitter account settings.");
            setPluginState(false);
            return;
              }

              twttrService = TwitterHelper.CreateClient(CONSUMER_KEY, CONSUMER_SECRET, twttrAccessToken.Token, twttrAccessToken.Secret);
              consoleWrite("Twitter client created successfully.");
        }
Exemplo n.º 13
0
        /// <summary>
        /// リクエストトークンを取得する
        /// </summary>
        /// <param name="consumer"></param>
        /// <returns></returns>
        public string RetrieveRequestToken( ref OAuthConsumer consumer )
        {
            // リクエストの作成とレスポンスの取得
            HttpWebRequest webreq = CreateRequest( ReqestToken, consumer, GET, "", RequestFormatAuth );
            string result = GetResponse( webreq );

            // oauth_tokenとoauth_token_secretを取得
            Match match = Regex.Match( result, @"oauth_token=(.*?)&oauth_token_secret=(.*?)&oauth_callback.*" );
            consumer.SetTokenWithSecret( match.Groups[1].Value, match.Groups[2].Value );

            // 認証用URLを返す
            return Authorize + "?" + result;
        }
Exemplo n.º 14
0
        /// <summary>
        /// リクエストを取得
        /// </summary>
        /// <param name="uri"></param>
        /// <param name="consumer"></param>
        /// <returns></returns>
        public string RetrieveRequest( string uri, OAuthConsumer consumer )
        {
            HttpWebRequest webreq = CreateRequest( uri, consumer, POST, "", RequestFormatRequest );
            webreq.Headers.Add( "Authorization", "OAuth " + oauth.AuthorizationRequestParameters );

            return GetResponse( webreq );
        }
Exemplo n.º 15
0
        /// <summary>
        /// リクエストの作成
        /// </summary>
        /// <param name="uri"></param>
        /// <param name="consumer"></param>
        /// <param name="method"></param>
        /// <param name="pin"></param>
        /// <returns></returns>
        private HttpWebRequest CreateRequest( string uri, OAuthConsumer consumer, string method, string pin, string format )
        {
            string signature = oauth.GenerateSignature( new Uri( uri ), consumer, method, pin );

            string request = string.Format( format, oauth.NormalizedRequestParameters, signature );
            string requestURL = uri + request;
            HttpWebRequest webreq = (System.Net.HttpWebRequest)WebRequest.Create( requestURL );
            webreq.Method = method;

            return webreq;
        }
Exemplo n.º 16
0
 public OAuthRequest(OAuthConsumer consumer, string debugType)
     : base(debugType)
 {
     this._consumer = consumer;
 }
Exemplo n.º 17
0
        public void PINを取得後の認証のためのシグニチャ()
        {
            string pin = "0011696";

            OAuth.OAuthBase oauth = new TestingOAuth( "1281614602", "8715791" );

            OAuth.OAuthConsumer consumer = new OAuthConsumer( ConsumerKey, ConsumerSecret );
            consumer.SetTokenWithSecret( "021d4561687d6c5d328ad5b491624f30", "552ae19dc6f2b7736db9678bb4de2f00" );

            Uri uri = new Uri( AccessToken );
            string signature = oauth.GenerateSignature( uri, consumer, "POST", pin );

            Assert.AreEqual( "w9XSZS9loX/pyz6DtO2Q04QmDAw=", signature );
            Assert.AreEqual( "oauth_consumer_key=OKWyYVPvnpcBfbdmrJaNWx&oauth_nonce=8715791&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1281614602&oauth_token=021d4561687d6c5d328ad5b491624f30&oauth_verifier=0011696&oauth_version=1.0",
                oauth.NormalizedRequestParameters );
        }
Exemplo n.º 18
0
        public BTCTLink(string consumerKey, string consumerSecret, bool isBTCT, DebugHandler dh)
        {
            OAuthConfig oc;

            DebugHandler = dh;

            _consumerKey = consumerKey;
            _consumerSecret = consumerSecret;

            oc = new OAuthConfig("");
            oc.SiteUrl = "";
            oc.OauthVersion = "1.0";
            oc.OauthSignatureMethod = "HMAC-SHA1";
            oc.OauthCallback = "oob";
            oc.OauthScope = "all";
            oc.ConsumerKey = _consumerKey;
            oc.ConsumerSecret = _consumerSecret;
            _isBTCT = isBTCT;
            if (isBTCT)
            {
                _baseUrl = "https://btct.co/";
                _coin = "BTC";
            }
            else
            {
                _baseUrl = "https://www.litecoinglobal.com/";
                _coin = "LTC";
            }
            oc.RequestTokenUrl = _baseUrl + "oauth/request_token";
            oc.AccessTokenUrl = _baseUrl + "oauth/access_token";
            oc.UserAuthorizationUrl = _baseUrl + "authorize";

            _oauthConsumer = new OAuthConsumer(oc, "");
            _authStatus = AuthStatusType.AS_NONE;
        }
Exemplo n.º 19
0
        public void データ取得のためのシグニチャ()
        {
            const string Diagrams = "http://cacoo.com/api/v1/diagrams.xml";

            OAuth.OAuthBase oauth = new TestingOAuth( "1281615317", "2677625" );

            OAuthConsumer consumer = new OAuthConsumer( ConsumerKey, ConsumerSecret );
            consumer.SetTokenWithSecret( "f1b3a9fdb759dbd0c1818f7cdef307c0", "2e55a9ea2e9c286abfedadffecf15f74" );

            Uri uri = new Uri( Diagrams );
            string signature = oauth.GenerateSignature( uri, consumer, "POST", "" );

            Assert.AreEqual( "YRhAaq8P+fN4DgkFhaF6x+EH1qA=", signature );
            Assert.AreEqual( "oauth_consumer_key=\"OKWyYVPvnpcBfbdmrJaNWx\", oauth_nonce=\"2677625\", oauth_signature_method=\"HMAC-SHA1\", oauth_timestamp=\"1281615317\", oauth_token=\"f1b3a9fdb759dbd0c1818f7cdef307c0\", oauth_version=\"1.0\", oauth_signature=\"YRhAaq8P%2BfN4DgkFhaF6x%2BEH1qA%3D\"",
                oauth.AuthorizationRequestParameters );
        }