Over the weekend, I wrote an actionscript library for client implementations of OAuth. It’s currently untested, but I’d love to see a few people help me keep it up to date & bug free, if anyone’s interested.

oauth-as3 Google Code page

Help make me popular:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Pownce
  • Slashdot
  • StumbleUpon
  • Technorati
  • TwitThis

This entry was posted on Monday, April 28th, 2008 at 2:42 pm and is filed under Projects. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

40 Responses to “OAuth Actionscript library”

  1. Ryan Stewart on April 28th, 2008 at 3:36 pm

    Very cool!!! I was hoping to work on this but never got to it, so thanks for posting it.

    =Ryan
    rstewart@adobe.com

  2. Kiall Mac Innes on June 3rd, 2008 at 8:22 am

    Great stuff! I was dreading having to write one of these myself! If I run into any issues you can expect some patches…

    Kiall

  3. Gwoo on June 21st, 2008 at 7:58 am

    Great work. I found a couple issues and I would be happy to get involved with the project. I’m hanging out in #flex on efnet :) Thanks for the effort.

  4. Edd Parris on July 25th, 2008 at 12:08 pm

    Hi

    Are there any examples of using this about?
    Im new to OAuth and just brushing up on my as skills, having a bit of trouble working out how to get this working.

    Thanks
    Edd

  5. Takashi on September 15th, 2008 at 5:07 pm

    Hi

    I’m trying to use this great library with MySpace Open Social API, but i’m having a problem with getting the right ‘oauth_signature’.

    MySpace provide developers with OAuth Testing Tool and when i request the request token from the tool page, it always works.

    I tried to use the same value for all the required parameters(oauth_consumer_key, oauth_nonce, oauth_signature_method, oauth_timestamp) but ‘oauth_signature’ never matches with the one MySpace testing tool generates from those parameters. So my request always ends up with 401(“signature_invalid”).

    I went through the library code and it all looks fine to me.
    Is anyone having the same problem?

    Thanks,
    Takashi

  6. Takashi on September 16th, 2008 at 12:39 pm

    Just a follow up on my previous post.
    If i delegate the HMAC_SHA1 encoding part to OAuth JavaScript Library(http://oauth.googlecode.com/svn/code/javascript), using External Interface, everything works.

    So I believe there is something wrong with the implementation of AS3 HMAC_SHA1 encoding.

  7. Antoni Jakubiak on January 8th, 2009 at 7:52 pm

    Takashi:

    as3crypto library works fine – tested versus PHP

  8. Brian on January 13th, 2009 at 12:49 pm

    I noticed someone asked about this but there’s no response. Does anyone have a working example or some instructions they can provide on how to use this set of classes?

  9. Shan on January 13th, 2009 at 1:31 pm

    I have no examples at the moment.

  10. dazsnow on February 16th, 2009 at 5:20 am

    It would be really useful to have a simple working example to show… surely if you’ve tested it you could provide us with something? I’m running into problems with crypto… fails to generate the signature everytime and i cannot fathom why.

    thanks

  11. An OpenID Login Component for Flex | Ryan Stewart - Rich Internet Application Mountaineer on February 19th, 2009 at 2:44 am

    [...] to add OpenID to your Flex applications. And for those of you interested in OAuth, iotashan has an OAuth-AS3 library that works pretty [...]

  12. JQ on April 28th, 2009 at 3:21 pm

    Thanks for building this. I’m a little confused on doing POST methods.
    for POST, do we only need to say:
    var request:OAuthRequest = new OAuthRequest(“POST”, ….) ?

    Do I need to modify anything here:
    url = request.buildRequest
    (new OAuthSignatureMethod_HMAC_SHA1(), OAuthRequest.RESULT_TYPE_URL_STRING);

    Thanks!

  13. Fabianv on April 30th, 2009 at 2:01 am

    Hey man thanks for this. However, are there examples anywhere? I’m trying to use this with the Twitter API because not of the Twitter Libraries for AS3 support OAuth yet :(

    Any ideas? thanks

  14. onelix on May 4th, 2009 at 8:51 pm

    hey!, any good tutorial for this api?

  15. Chris on May 19th, 2009 at 1:20 pm

    This code doesn’t quite seem to work yet — at least not for POST updates. Maybe it’s the Crypto library, maybe not, but I haven’t had any luck against Twitter’s /statuses/update.xml yet, though GETs look fine so far. The culprit indeed looks like Crypto, but I’m not 100% sure yet.

    If I come up with a solution, I’ll post back. Many thanks, though — there’s a lot of good work here nonetheless. :)

  16. Chris on May 19th, 2009 at 4:08 pm

    Aha! If anyone’s having issues with POSTing to Twitter with this library (specifically getting a 401 response accompanied by the message “Failed to validate oauth signature or token” on posting to /statuses/update.*), I’ve found a fix: getSignableParameters() neglects to URL-encode its parameter values, so the signatures don’t match.

    Changing this line in OAuthRequest.as (my line 194):

    aParams.push(param + “=” + _requestParams[param].toString());

    … to this:

    aParams.push(param + “=” + URLEncoding.encode(_requestParams[param].toString()));

    … did the trick. Hope it helps! I lost a good several hours on this one. :)

  17. Shan on May 22nd, 2009 at 8:48 am

    @Chris:

    I made & checked in your change. Thanks for contributing!

  18. Daniel on May 25th, 2009 at 7:24 am

    For anyone trying to POST to Twitter, or maybe any other oAuth application, make sure to use URLRequest and URLLoader to load your data. Also, make sure to set:

    URLRequest.data = oAuth.buildRequest(new OAuthSignatureMethod_HMAC_SHA1(), “post”);

    Do NOT use the urlVariables option and DO NOT use HTTPService if you are doing this in Flex as I was. The HTTPService incorrectly orders and encodes the POST data and I could not find a way around it. Hope this helps someone else!

  19. Shan on May 25th, 2009 at 9:52 am

    @Daniel:

    I’m going to look into this. I know that urlVariables does not encode strings according to the oAuth spec. I probably should just take that option out of the buildRequest() method.

  20. Chris on June 2nd, 2009 at 6:37 am

    @Shan: Thanks for incorporating my change! I’d like to join the Google Code project as well if possible. Could you contact me? I’m cnunciato on Twitter — just followed you as well. Thanks man. Cheers and thanks again for the good work!

  21. Vapor on June 3rd, 2009 at 7:53 am

    I’ve been trying to use the package to perform a POST to the /statuses/update.xml function on Twitter. After banging my head for several hours, I found that the URLEncoding class is encoding spaces to pluses. So, “This is a test” ends up being “This+is+a+test”. While this is normally fine, that is not the URL encoding spec that Twitter uses and it causes a failure of the signature verification during the /status/update.xml. I changed my local copy to use “%20″ and it works perfectly now.

    Thanks for all your hard work!!

  22. Shan on June 4th, 2009 at 10:06 am

    @Vapor:

    I’ve modified the URLEncoding class to allow for you to pick between + or %20, and it defaults now to %20.

    Shan

  23. edmond on June 8th, 2009 at 12:15 am

    I am trying to put together this oauth library with MySpace opensocial client. If someone has done that before, would you mind sharing some sample code? Thanks in advance.

  24. Sönke on June 10th, 2009 at 9:41 am

    Twitter just changed authentication for desktop clients. Now the user got a key which he has to put into your app and you have to add {oauth_verifier:THE_PIN} as requestParameter.

  25. Shan on June 11th, 2009 at 9:32 am

    @Sönke: Yeah, it’s the new oAuth standard. Pretty much everyone will be doing it now. I’ll update when I get time.

  26. Tim on June 29th, 2009 at 4:16 pm

    Hi,

    Thanks so much for this library, it’s been fantastic for my little twitter app I’m building in AIR. However there is one thing that is worrying me now. Do we have to go and get the user to log in EVERY time they open the local AIR app to get a new pin? I’ve done some testing and it appears that this is the case.

    Is there anyway that we can save details locally so we can avoid this as this is a horrible user experience.

    Sorry – I’m new to OAuth and I’m still getting my head around it.

    Cheers in advance!

    Tim

  27. Ryan on July 1st, 2009 at 1:31 pm

    Hey all,

    I have noticed a few requests for an example, but, at last, no example has been officially given. At the risk of sounding redundant, could you please post a example of the implementation library. This would really really really help.

    Thanks,

    Ryan

  28. Sönke on July 7th, 2009 at 11:52 am

    I have build a high level AS3/Flex library which uses your awesome library: http://github.com/srohde/OAuth/tree/master

    I also have no public example yet but will blog something this week.

  29. Sönke Rohde » High level AS3/Flex library for OAuth with Twitter from AIR on July 8th, 2009 at 3:22 am

    [...] a bit of research a came across the awesome open source library oauth-as3. There were no examples yet but I remembered an Email from my friend Claus with a link to this [...]

  30. Rob Linton on August 20th, 2009 at 4:38 pm

    I played around with this library and came across a bug when using UTF-8 and extended characters. Using encodeURIComponent (http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/package.html) instead of the included URLEncoding library solved them for me.

    Cheers.

  31. Denis Borisenko on August 31st, 2009 at 2:47 am

    Rob Linton, your solution is not completely good. Yes, we can use encodeURIComponent() instead of the URLEncoding library and we can use extended characters. But in this case, we can not use special characters, such as: “!”, “*”, possibly some others.

  32. Denis Borisenko on September 4th, 2009 at 12:08 pm

    I understand the problem with extended UTF-8 chracters. I can offer a solution, which I posted in my blog:
    http://blog.dborisenko.com/en/2009/09/04/extended-utf-8-in-oauth-actionscript-library/

  33. Extended UTF-8 in OAuth ActionScript library on September 4th, 2009 at 2:13 pm

    [...] library of Iotashan doesn’t work correct with Extended UTF-8 characters. If you use this characters (for example, [...]

  34. Shan on September 4th, 2009 at 2:31 pm

    I just made Denis’s changes, and committed it to the project. Thanks again, Denis!

    http://code.google.com/p/oauth-as3/source/detail?r=13

  35. Dorian on September 25th, 2009 at 9:53 am

    thanks for this great library. I’ve used it for my SoundCloud API wrapper
    http://github.com/dasflash/Soundcloud-AS3-API/

    But I had to make one change to get it to work with the SoundCloud API: The parameter names of the signed parameters need to be URL-encoded as well before signing them. That’s probably almost never a problem because almost nobody uses special characters in the parameter name, but SoundCloud does ;) e.g. playlist[title]=foo

    You can simply change line 182 of OAuthRequest class to:

    aParams.push( URLEncoding.encode(param) + “=” + URLEncoding.encode(_requestParams[param].toString()));

    and everything works fine

  36. Denis Borisenko on September 25th, 2009 at 1:29 pm

    hey! It’s me again :) I didn’t draw attention the first time, but for some reason the character «\\» was not displayed in my post. To be exactly sure, it is better to copy the methods from this file.

    Thanks,
    Denis

  37. Rob Gabbard on September 26th, 2009 at 5:50 am

    As Denis noted, there is a serious problem with the recent UTF-8 fix in URLEncoding.as. Here’s the fix for anyone until it gets updated in the project source….

    In URLEncoding.as, I believe….

    string = string.replace(/rn/g,’n');
    string = string.replace(/r/g,’n');

    … is supposed to be …

    string = string.replace(/\r\n/g,’\n’);
    string = string.replace(/\r/g,’\n’);

    This causes significant issues if you are encoding any string the has an
    ‘r’ in it.

  38. Rob Gabbard on September 26th, 2009 at 5:54 am

    Also… if you grab Denis’s original file linked in his post, you need to change…

    package com.dborisenko.utils
    {
    public class URLUtil

    … to …

    package org.iotashan.utils
    {
    public class URLEncoding
    {

    .. in order to use it in oauth-as3 and save it to the src/org/iotashan/utils folder.

    Rob

  39. Marcin on October 26th, 2009 at 3:47 am

    Rob thanks for your great fidings, I hope this helps me with Shan’s lib. If anyone needs OAuth debugging tools, check this out:

    MySpace OAuth Debugging Tool:
    http://wiki.developer.myspace.com/index.php?title=OAuth_Testing_Tool

    Official OAuth libs with example services in many langs: http://code.google.com/p/oauth/
    test ride here: http://term.ie/oauth/example/

  40. Philip on July 8th, 2010 at 3:53 pm

    Google are returning me a request token of “4%252FcMF4t6Bc0i_ojIjMtZ4l1tB3ut4x” which plays havoc with subsequent url encoding! Notice the “%” included in the token. Are Google at fault here?

    More info on my issue here: http://code.google.com/p/oauth-as3/issues/detail?id=7

Leave a Reply