Don't ask for the requestToken if we haven't told OAuthPanel which connection to...
[potlatch2.git] / net / systemeD / potlatch2 / save / OAuthPanel.mxml
index c01a542febb431b406d9c4e39e98af22e45ee5c7..f972f927ffa220c0ef0a881d4e24e473394715a0 100644 (file)
@@ -81,6 +81,7 @@
         private var _accessToken:OAuthToken;
         private var authoriseURL:String;
         private var lastHTTPStatus:int = 0;
+        private var waiting:Boolean = false;
         
         public static var ACCESS_TOKEN_EVENT:String = "gotAccessToken";
         
@@ -91,6 +92,7 @@
         
                public function setConnection(connection:Connection):void {
                        this.connection=connection;
+                       if (waiting) { waiting=false; getRequestToken(); }
                }
 
         private function openURL(url:String):void {
                }
         
         private function getRequestToken():void {
+            if (!connection) { waiting=true; return; } // in case the connection hasn't been set yet
+
             var sig:IOAuthSignatureMethod = new OAuthSignatureMethod_HMAC_SHA1();
             var consumer:OAuthConsumer = getConsumer();
-            var url:String = Connection.getParam("oauth_request_url", "http://127.0.0.1:3000/oauth/request_token");
+            var url:String = connection.getParam("oauth_request_url", "http://127.0.0.1:3000/oauth/request_token");
             
             var params:Object = new Object();
             var oauthRequest:OAuthRequest = new OAuthRequest("GET", url, params, consumer, null);
             trace("Yay! response: "+URLLoader(event.target).data);
             requestToken = getResponseToken(URLLoader(event.target));
             
-            var url:String = Connection.getParam("oauth_auth_url", "http://127.0.0.1:3000/oauth/authorize");            
+            var url:String = connection.getParam("oauth_auth_url", "http://127.0.0.1:3000/oauth/authorize");            
             link.label = url;
                        authoriseURL = url + "?oauth_token="+requestToken.key;
                        progress.visible = false;
         private function getAccessToken():void {
             var sig:IOAuthSignatureMethod = new OAuthSignatureMethod_HMAC_SHA1();
             var consumer:OAuthConsumer = getConsumer();
-            var url:String = Connection.getParam("oauth_access_url", "http://127.0.0.1:3000/oauth/access_token");
+            var url:String = connection.getParam("oauth_access_url", "http://127.0.0.1:3000/oauth/access_token");
 
             var oauthRequest:OAuthRequest = new OAuthRequest("GET", url, null, consumer, requestToken);
             var urlStr:Object = oauthRequest.buildRequest(sig, OAuthRequest.RESULT_TYPE_URL_STRING)
         }
         
         private function getConsumer():OAuthConsumer {
-            var key:String = Connection.getParam("oauth_consumer_key", "");
-            var secret:String = Connection.getParam("oauth_consumer_secret", "");
+            var key:String = connection.getParam("oauth_consumer_key", "");
+            var secret:String = connection.getParam("oauth_consumer_secret", "");
             return new OAuthConsumer(key, secret);
         }