AndroidAuthenticatorpublic class AndroidAuthenticator extends Object implements AuthenticatorAn Authenticator that uses {@link AccountManager} to get auth
tokens of a specified type for a specified account. |
Fields Summary |
---|
private final android.content.Context | mContext | private final android.accounts.Account | mAccount | private final String | mAuthTokenType | private final boolean | mNotifyAuthFailure |
Methods Summary |
---|
public android.accounts.Account | getAccount()Returns the Account being used by this authenticator.
return mAccount;
| public java.lang.String | getAuthToken()
final AccountManager accountManager = AccountManager.get(mContext);
AccountManagerFuture<Bundle> future = accountManager.getAuthToken(mAccount,
mAuthTokenType, mNotifyAuthFailure, null, null);
Bundle result;
try {
result = future.getResult();
} catch (Exception e) {
throw new AuthFailureError("Error while retrieving auth token", e);
}
String authToken = null;
if (future.isDone() && !future.isCancelled()) {
if (result.containsKey(AccountManager.KEY_INTENT)) {
Intent intent = result.getParcelable(AccountManager.KEY_INTENT);
throw new AuthFailureError(intent);
}
authToken = result.getString(AccountManager.KEY_AUTHTOKEN);
}
if (authToken == null) {
throw new AuthFailureError("Got null auth token for type: " + mAuthTokenType);
}
return authToken;
| public void | invalidateAuthToken(java.lang.String authToken)
AccountManager.get(mContext).invalidateAuthToken(mAccount.type, authToken);
|
|