OpenID for android apps that require SignIn

2019-01-30 15:56发布

问题:

I am a fresh developer on Googles Android Platform - my HTC Desire arrived last week.

Now i need a way to sign in to my existing application (Java, currently running on jetty). The server Application is developed using spring security 3.0.2

In my case, i want to support the following: If a user has set up his Android phone with a googlemail/google-Account (and most users do) i want to use this account credentials to automagically log in to my server app.

Is there any Android framework supporting that use-case? Or are there any alternatives?

I read: http code.google.com intl/de-DE/apis/accounts/docs/OpenID.html

How we do sign in with an app on google AppEngine is described here: http://blog.notdot.net/2010/05/Authenticating-against-App-Engine-from-an-Android-app

回答1:

I think what you want is to use AccountManager

To find out what type the google account is, use something like:

AuthenticatorDescription[] types = mAccountManager.getAuthenticatorTypes(); //
for (AuthenticatorDescription type : types) {
  Log.d("account types", type.type);
}

Then do something like

AccountManager mAccountManager = AccountManager.get(context);
Account[] mAccounts = AccountManager.get(context).getAccountsByType("com.google");
// Choose which account to use if there are multiple google accounts registered, save to Account mAccount
AccountManagerFuture<options> response = mAccountManager.getAuthToken(mAccount, type, options, activity, mCallback, mHandler); // define callback and handler yourself for where to return

When the user reaches mCallback in your mHandler, the login process is done. The usual google login dialogue will be used if the user is not already logged in to his/her Google account.

Try it out for yourself and let me know if it helped you!



回答2:

Here is an OPENID java API : Here is the link:http://code.google.com/p/openid4java/



回答3:

I'm not sure I understand where you want the user to be logged on.

Note that you can't assume which web browser will be used (default browser, opera mobile, manufacturer browser, etc.) If you only offer an web site, it is the web browser responsibility to know the user. Most people I have already logged in their google account. Android is sort of unrelelated here.

If you want your Android application to connect to a web service without prompting for a login/password, you can't achieve this with openID. I suggest oauth for this use case.