Permalink
Browse files

initial lib

  • Loading branch information...
1 parent e930586 commit 2dfed7edecd513e9e4d0969f82d9fe258202ac2d @srohde committed Jul 1, 2009
View
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<actionScriptProperties mainApplicationPath="OAuth.as" projectUUID="cd2f620e-af74-4d06-b26e-3251bc79255a" version="6">
+ <compiler additionalCompilerArguments="" autoRSLOrdering="true" copyDependentFiles="false" generateAccessible="false" htmlExpressInstall="true" htmlGenerate="false" htmlHistoryManagement="false" htmlPlayerVersionCheck="true" includeNetmonSwc="true" outputFolderPath="bin" sourceFolderPath="src" strict="true" targetPlayerVersion="0.0.0" useApolloConfig="true" useDebugRSLSwfs="true" verifyDigests="true" warn="true">
+ <compilerSourcePath/>
+ <libraryPath defaultLinkType="0">
+ <libraryPathEntry kind="4" path=""/>
+ <libraryPathEntry kind="1" linkType="1" path="libs"/>
+ </libraryPath>
+ <sourceAttachmentPath/>
+ </compiler>
+ <applications>
+ <application path="OAuth.as"/>
+ </applications>
+ <modules/>
+ <buildCSSFiles/>
+</actionScriptProperties>
View
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<flexLibProperties version="1">
+ <includeClasses>
+ <classEntry path="org.flaircode.oauth.IOAuth"/>
+ <classEntry path="org.flaircode.oauth.OAuth"/>
+ <classEntry path="org.flaircode.oauth.OAuthLoader"/>
+ <classEntry path="org.flaircode.oauth.OAuthUtil"/>
+ </includeClasses>
+ <includeResources/>
+ <namespaceManifests/>
+</flexLibProperties>
View
@@ -0,0 +1,5 @@
+bin
+
+
+
+
View
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>OAuth</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>com.adobe.flexbuilder.project.flexbuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>com.adobe.flexbuilder.project.flexlibnature</nature>
+ <nature>com.adobe.flexbuilder.project.actionscriptnature</nature>
+ </natures>
+</projectDescription>
@@ -0,0 +1,3 @@
+#Wed Jul 01 17:08:49 CEST 2009
+eclipse.preferences.version=1
+encoding/<project>=utf-8
View
Binary file not shown.
@@ -0,0 +1,57 @@
+package org.flaircode.oauth
+{
+ import flash.net.URLRequest;
+
+ import mx.rpc.AsyncToken;
+
+ import org.iotashan.oauth.OAuthToken;
+
+ /**
+ * OAuth interface
+ * @author soenkerohde
+ * @see org.flairtweet.oauth.OAuth
+ *
+ */
+ public interface IOAuth
+ {
+
+ /**
+ *
+ * @param url for Twitter http://twitter.com/oauth/request_token
+ * @return AsyncToken which will return result typed OAuthToken
+ * @see org.iotashan.oauth.OAuthToken
+ *
+ */
+ function getRequestToken(url:String):AsyncToken;
+
+ /**
+ *
+ * @param url for Twitter http://twitter.com/oauth/authorize
+ * @param requestTokenKey Key from a previously retrieved request token
+ * @return Can be opened in the browser or with AIR with the HTML control
+ *
+ */
+ function getAuthorizeRequest(url:String, requestTokenKey:String):URLRequest;
+
+ /**
+ *
+ * @param url for Twitter http://twitter.com/oauth/access_token
+ * @param requestToken previously retrieved request token
+ * @param pin 6 digit number the user has retrieved from the authorize page
+ * @return AsyncToken which will return result typed OAuthToken
+ *
+ */
+ function getAccessToken(url:String, requestToken:OAuthToken, pin:int):AsyncToken;
+
+ /**
+ *
+ * @param method GET,POST,UPDATE,DELETE
+ * @param url for Twitter friends timeline and JSON result https://twitter.com/statuses/friends_timeline.json
+ * @param accessToken
+ * @param requestParams
+ * @return
+ *
+ */
+ function buildRequest(method:String, url:String, accessToken:OAuthToken, requestParams:Object = null):URLRequest;
+ }
+}
@@ -0,0 +1,138 @@
+package org.flaircode.oauth
+{
+ import flash.events.Event;
+ import flash.events.IOErrorEvent;
+ import flash.net.URLLoader;
+ import flash.net.URLRequest;
+
+ import mx.logging.ILogger;
+ import mx.logging.Log;
+ import mx.rpc.AsyncToken;
+ import mx.rpc.IResponder;
+ import mx.rpc.events.ResultEvent;
+
+ import org.iotashan.oauth.OAuthConsumer;
+ import org.iotashan.oauth.OAuthRequest;
+ import org.iotashan.oauth.OAuthSignatureMethod_HMAC_SHA1;
+ import org.iotashan.oauth.OAuthToken;
+
+ public class OAuth implements IOAuth
+ {
+
+ private static const logger:ILogger = Log.getLogger("OAuth");
+
+ private var signature:OAuthSignatureMethod_HMAC_SHA1 = new OAuthSignatureMethod_HMAC_SHA1();
+
+ private var _consumerKey:String;
+ private var _consumerSecret:String;
+ private var _consumer:OAuthConsumer;
+
+ public function set consumerKey(key:String):void
+ {
+ _consumerKey = key;
+ }
+
+ public function set consumerSecret(secret:String):void
+ {
+ _consumerSecret = secret;
+ }
+
+ protected function get consumer():OAuthConsumer
+ {
+ if(_consumer == null)
+ {
+ if(_consumerKey != null && _consumerSecret != null)
+ _consumer = new OAuthConsumer(_consumerKey, _consumerSecret);
+ else
+ throw new Error("consumerKey/Secret not set.");
+ }
+ return _consumer;
+ }
+
+ public function OAuth()
+ {
+ }
+
+ public function buildRequest(method:String, url:String, accessToken:OAuthToken, requestParams:Object = null):URLRequest
+ {
+ var r:OAuthRequest = new OAuthRequest("GET", url, null, consumer, accessToken);
+ var req:URLRequest = new URLRequest(r.buildRequest(signature));
+ return req;
+ }
+
+ /**
+ * build the URLRequest for website authorization
+ *
+ * @param requestTokenKey
+ * @return URLRequest for authorize Twitter page
+ *
+ */
+ public function getAuthorizeRequest(url:String, requestTokenKey:String):URLRequest
+ {
+ var req:URLRequest = new URLRequest(url + "?oauth_token=" + requestTokenKey);
+ return req;
+ }
+
+ /**
+ * gets the RequestToken based on the defined consumerKey and consumerSecret
+ *
+ * @param url
+ * @return result is OAuthToken
+ *
+ */
+ public function getRequestToken(url:String):AsyncToken
+ {
+ var asyncToken:AsyncToken = new AsyncToken();
+
+ var r:OAuthRequest = new OAuthRequest("GET", url, null, consumer, null);
+ var req:URLRequest = new URLRequest(r.buildRequest(signature));
+ var loader:URLLoader = new URLLoader();
+
+ loader.addEventListener(Event.COMPLETE, function(e:Event):void
+ {
+ var result:OAuthToken = OAuthUtil.getTokenFromResponse(e.currentTarget.data as String);
+ var re:ResultEvent = new ResultEvent(ResultEvent.RESULT, false, true, result);
+ for each(var responder:IResponder in asyncToken.responders)
+ {
+ responder.result(re);
+ }
+
+ });
+
+ loader.load(req);
+ return asyncToken;
+ }
+
+
+
+ public function getAccessToken(url:String, requestToken:OAuthToken, pin:int):AsyncToken
+ {
+ var asyncToken:AsyncToken = new AsyncToken();
+
+ var r:OAuthRequest = new OAuthRequest("GET", url, {oauth_verifier:pin}, consumer, requestToken);
+ var req:URLRequest = new URLRequest(r.buildRequest(signature));
+ var loader:URLLoader = new URLLoader();
+ loader.addEventListener(Event.COMPLETE, function(e:Event):void
+ {
+ var result:OAuthToken = OAuthUtil.getTokenFromResponse(e.currentTarget.data as String);
+ var re:ResultEvent = new ResultEvent(ResultEvent.RESULT, false, true, result);
+ for each(var responder:IResponder in asyncToken.responders)
+ {
+ responder.result(re);
+ }
+
+ });
+ loader.addEventListener(IOErrorEvent.IO_ERROR, function(e:IOErrorEvent):void
+ {
+ for each(var resp:IResponder in asyncToken.responders)
+ {
+ resp.fault(null);
+ }
+ });
+ loader.load(req);
+
+ return asyncToken;
+ }
+
+ }
+}
@@ -0,0 +1,90 @@
+package org.flaircode.oauth
+{
+ import flash.events.Event;
+ import flash.html.HTMLLoader;
+ import flash.net.URLRequest;
+
+ import mx.core.UIComponent;
+
+ /**
+ * A complete event is dispatched when the website has been loaded.
+ */
+ [Event(name="complete")]
+
+ /**
+ * OAuthLoader
+ *
+ * HTMLLoader wrapper class because HTML loader does not implement IUIComponent
+ */
+ public class OAuthLoader extends UIComponent
+ {
+ /**
+ * Constructor
+ */
+ public function OAuthLoader()
+ {
+ super();
+ }
+
+ /**
+ * @private
+ * HTMLLoader instance
+ */
+ private var htmlLoader:HTMLLoader;
+
+ /**
+ * Create the HTMLLoader and makes it a child of this UIComponent instance.
+ */
+ override protected function createChildren():void
+ {
+ if(htmlLoader == null)
+ {
+ htmlLoader = new HTMLLoader();
+ htmlLoader.width = 640;
+ htmlLoader.height = 480;
+ addChild(htmlLoader);
+
+ htmlLoader.addEventListener(Event.COMPLETE, completeHandler);
+ }
+ }
+
+ /**
+ * define default width/height
+ */
+ override protected function measure():void
+ {
+ measuredWidth = 640;
+ measuredHeight= 480;
+ }
+
+ /**
+ * resize to fit available space
+ */
+ override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
+ {
+ super.updateDisplayList(unscaledWidth, unscaledHeight);
+ htmlLoader.width = unscaledWidth;
+ htmlLoader.height= unscaledHeight;
+ }
+
+ /**
+ * re-dispatch bubbling event
+ */
+ private function completeHandler(event:Event) : void
+ {
+ dispatchEvent(new Event(Event.COMPLETE));
+ }
+
+ /**
+ *
+ * @param request
+ *
+ */
+ public function load(request:URLRequest) : void
+ {
+ if(htmlLoader == null)
+ createChildren();
+ htmlLoader.load(request);
+ }
+ }
+}
Oops, something went wrong.

0 comments on commit 2dfed7e

Please sign in to comment.