3

There are plenty of samples out there, especially for Twitter. This one seems to be one of the most complete so I've been hacking on it:

https://github.com/brione/Brion-Learns-OAuth

However, all of the samples are basically proof of concept code. They all have rough edges like leaving a split task stack when you launch through the browser. I've got the app I'm playing with working mostly the way I want it to by declaring it singleTask and forcing the browser to call back into the original task instead of starting up a new activity:

<activity android:name=".MainActivity"
              android:label="@string/app_name"
              android:launchMode="singleTask">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
</activity>

However I'm wondering if there are better ways to handle this, like popping up a modal WebView to take the user through the auth process?

I'm assuming that for Twitter in particular the "right" thing to do is probably to swap to xauth. But I still would like to know, generally speaking, is there a best-practice production quality OAuth implementation for Android out there?

mikerowehl
  • 2,222
  • 1
  • 17
  • 20

2 Answers2

1

Maybe the following example will be of any help:

https://github.com/ddewaele/AndroidOAuthFlowSample/tree/latitude_branch

tamsler
  • 1,275
  • 1
  • 18
  • 26
  • Thanks for the pointer. Unfortunately I haven't dug into maven yet, so I can't fully test it out. But good to see another batch of code that takes similar approaches, and adds a few techniques I haven't tried out yet. Thanks! – mikerowehl Feb 07 '11 at 17:29
1

Been there, done that. The android examples floating around are almost always miss some important detail or are simply not up to date. That's why I wrote an easy to follow summary how I did OAuth on android a few days ago:

http://nilvec.com/implementing-client-side-oauth-on-android/

I can also publish the OAuth helper class I implemented if anyone's interested.

ldx
  • 3,984
  • 23
  • 28
  • Please do, not sure I fully understand what's going on there without the manifest. Whenever I tried to do something similar I ended up with the MyActivity activity stacked on a browser activity unless I tweaked the launch settings for MyActivity. If there's a better way would love to try it. – mikerowehl Feb 09 '11 at 11:27
  • If that's the only problem, you could try using FLAG_ACTIVITY_NO_HISTORY e.g. Intent i = new Intent("android.intent.action.VIEW", Uri.parse(uristring)); i.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); startActivity(i); – ldx Feb 09 '11 at 11:52