@Override public Bundle getAuthToken(AccountAuthenticatorResponse response, Account account, String authTokenType, Bundle options) throws NetworkErrorException { final AccountManager am = AccountManager.get(mContext); String authToken = am.peekAuthToken(account, authTokenType); if (TextUtils.isEmpty(authToken)) { final String password = am.getPassword(account); if (password != null) { //request user sign in RelianceAuthToken tokenRequester = new RelianceAuthToken(Utility.getDeviceId(mContext)); try { authToken = tokenRequester.requestToken(account.name, password); } catch (JSONException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } } if (TextUtils.isEmpty(authToken)) { //show the login screen final Intent intent = new Intent(mContext, AccountLoginActivity.class); intent.putExtra(AccountLoginActivity.ARG_ACCOUNT_TYPE, account.type); intent.putExtra(AccountLoginActivity.ARG_AUTH_TYPE, authTokenType); intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response); final Bundle bundle = new Bundle(); bundle.putParcelable(AccountManager.KEY_INTENT, intent); return bundle; } else { //return the auth token final Bundle result = new Bundle(); result.putString(AccountManager.KEY_ACCOUNT_NAME, account.name); result.putString(AccountManager.KEY_ACCOUNT_TYPE, account.type); result.putString(AccountManager.KEY_AUTHTOKEN, authToken); return result; } }