@Test public void invalidateAuthToken_multipleTokenTypesSameToken() { Account account = new Account("name", "type1"); shadowOf(am).addAccount(account); am.setAuthToken(account, "token_type_1", "token1"); am.setAuthToken(account, "token_type_2", "token1"); assertThat(am.peekAuthToken(account, "token_type_1")).isEqualTo("token1"); assertThat(am.peekAuthToken(account, "token_type_2")).isEqualTo("token1"); // invalidate token1 am.invalidateAuthToken("type1", "token1"); assertThat(am.peekAuthToken(account, "token_type_1")).isNull(); assertThat(am.peekAuthToken(account, "token_type_2")).isNull(); }
@Test public void invalidateAuthToken_multipleTokens() { Account account = new Account("name", "type1"); shadowOf(am).addAccount(account); am.setAuthToken(account, "token_type_1", "token1"); am.setAuthToken(account, "token_type_2", "token2"); assertThat(am.peekAuthToken(account, "token_type_1")).isEqualTo("token1"); assertThat(am.peekAuthToken(account, "token_type_2")).isEqualTo("token2"); // invalidate token1 am.invalidateAuthToken("type1", "token1"); assertThat(am.peekAuthToken(account, "token_type_1")).isNull(); assertThat(am.peekAuthToken(account, "token_type_2")).isEqualTo("token2"); // invalidate token2 am.invalidateAuthToken("type1", "token2"); assertThat(am.peekAuthToken(account, "token_type_1")).isNull(); assertThat(am.peekAuthToken(account, "token_type_2")).isNull(); }
@Test public void invalidateAuthToken_multipleAccounts() { Account account1 = new Account("name", "type1"); shadowOf(am).addAccount(account1); Account account2 = new Account("name", "type2"); shadowOf(am).addAccount(account2); am.setAuthToken(account1, "token_type_1", "token1"); am.setAuthToken(account2, "token_type_1", "token1"); assertThat(am.peekAuthToken(account1, "token_type_1")).isEqualTo("token1"); assertThat(am.peekAuthToken(account2, "token_type_1")).isEqualTo("token1"); // invalidate token for type1 account am.invalidateAuthToken("type1", "token1"); assertThat(am.peekAuthToken(account1, "token_type_1")).isNull(); assertThat(am.peekAuthToken(account2, "token_type_1")).isEqualTo("token1"); // invalidate token for type2 account am.invalidateAuthToken("type2", "token1"); assertThat(am.peekAuthToken(account1, "token_type_1")).isNull(); assertThat(am.peekAuthToken(account2, "token_type_1")).isNull(); }
@Test public void addAuthToken() { Account account = new Account("name", "type"); shadowOf(am).addAccount(account); am.setAuthToken(account, "token_type_1", "token1"); am.setAuthToken(account, "token_type_2", "token2"); assertThat(am.peekAuthToken(account, "token_type_1")).isEqualTo("token1"); assertThat(am.peekAuthToken(account, "token_type_2")).isEqualTo("token2"); }
@Test public void setAuthToken_shouldNotAddTokenIfAccountNotPresent() { Account account = new Account("name", "type"); am.setAuthToken(account, "token_type_1", "token1"); assertThat(am.peekAuthToken(account, "token_type_1")).isNull(); }
@Override public Bundle getAuthToken(AccountAuthenticatorResponse response, Account account, String authTokenType, Bundle options) throws NetworkErrorException { Bundle authBundle = new Bundle(); String authToken = AccountManager.get(context).peekAuthToken(account, authTokenType); if (!TextUtils.isEmpty(authToken)) { authBundle.putString(AccountManager.KEY_ACCOUNT_NAME, account.name); authBundle.putString(AccountManager.KEY_ACCOUNT_TYPE, account.type); authBundle.putString(AccountManager.KEY_AUTHTOKEN, authToken); } else { Intent authIntent = new Intent(context, AuthenticationActivity.class); authIntent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response); authBundle.putParcelable(AccountManager.KEY_INTENT, authIntent); } return authBundle; }
@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 (authToken != null && authToken.length() > 0) { final Bundle result = new Bundle(); result.putString(AccountManager.KEY_ACCOUNT_NAME, account.name); result.putString(AccountManager.KEY_ACCOUNT_TYPE, HatchetAuthenticatorUtils.ACCOUNT_TYPE); result.putString(AccountManager.KEY_AUTHTOKEN, authToken); return result; } /*final Intent intent = new Intent(mContext, TomahawkMainActivity.class); intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response); intent.putExtra(TomahawkService.AUTHENTICATOR_ID, TomahawkService.AUTHENTICATOR_ID_HATCHET); intent.putExtra(PARAMS_USERNAME, account.name); intent.putExtra(PARAMS_TYPE, authTokenType);*/ //bundle.putParcelable(AccountManager.KEY_INTENT, intent); return new Bundle(); }
public boolean isLoggedIn() { AccountManager am = AccountManager.get(TomahawkApp.getContext()); return am != null && getAccount() != null && am.peekAuthToken(getAccount(), AUTH_TOKEN_HATCHET) != null; }
@Override public Bundle getAuthToken(AccountAuthenticatorResponse response, Account account, String authTokenType, Bundle options) throws NetworkErrorException { final AccountManager am = AccountManager.get(context); String authToken = am.peekAuthToken(account, authTokenType); if (TextUtils.isEmpty(authToken)) { final String password = am.getPassword(account);
@Override public Bundle getAuthToken(AccountAuthenticatorResponse accountAuthenticatorResponse, Account account, String authTokenType, Bundle bundle) throws NetworkErrorException { String authToken = accountManager.peekAuthToken(account, authTokenType); if (TextUtils.isEmpty(authToken)) { try {
calumetExpirationTime = Integer.valueOf(mandellaExpirationTimeString); refreshToken = am.peekAuthToken(getAccount(), AUTH_TOKEN_HATCHET);
token = accountManager.peekAuthToken(account, IndieAuthActivity.TOKEN_TYPE);
if (object == null) { accountManager.invalidateAuthToken(property.getPackageKey(), accountManager.peekAuthToken(account.getAccount(), property.getPackageKey()));
case AUTH_TOKEN: // fallback to non blocking peek, used exclusively by AccountPropertiesManager.setAndNotify case PEEK_AUTH_TOKEN: return accountManager.peekAuthToken(account.getAccount(), AccountProperty.AUTH_TOKEN.getPackageKey()); case FUTURE_AUTH_TOKEN: return accountManager.getAuthToken(account.getAccount(), AccountProperty.AUTH_TOKEN.getPackageKey(), null, false, null, null);