当前位置: 动力学知识库 > 问答 > 编程问答 >

oauth 2.0 - Android AccountAuthenticator and OAuth2

问题描述:

I'm working on an Android app using the Windows Live services which uses OAuth2 authentication, therefore I don't have access to the users password. I would like to add the users account to the Android account manager but since I don't have access to the users password, its a spot of problem sticking to the default flow of the account manager i.e. to re-login the user if the auth token is no longer valid. Has anybody built an Android app that uses the account manager for a service that uses OAUth2 for verification? If so how did you handle this?

Thank you,

Regards,

Akshay

网友答案:

This is certainly doable. From the Android AccountManager documentation:

Many servers support some notion of an authentication token, which can be used to authenticate a request to the server without sending the user's actual password. (Auth tokens are normally created with a separate request which does include the user's credentials.) AccountManager can generate auth tokens for applications, so the application doesn't need to handle passwords directly. Auth tokens are normally reusable and cached by AccountManager, but must be refreshed periodically. It's the responsibility of applications to invalidate auth tokens when they stop working so the AccountManager knows it needs to regenerate them.

A bit of Googling also turns up a fairly detailed tutorial of how to do this:

http://blog.doityourselfandroid.com/2011/08/06/oauth-2-0-flow-android/

In addition, it is also discussed in one of the 2011 Google IO sessions which can be viewed online:

http://www.google.com/events/io/2011/sessions/best-practices-for-accessing-google-apis-on-android.html

The Google IO session is of course discussing Google APIs, but since your interested in OAuth2 what you learn there should be germane to your situation.

分享给朋友:
您可能感兴趣的文章:
随机阅读: