@Override public void invalidateAuthToken(String authToken) { mAccountManager.invalidateAuthToken(mAccount.type, authToken); } }
@Override public void invalidateAuthToken(String authToken) { mAccountManager.invalidateAuthToken(mAccount.type, authToken); } }
@Override public void invalidateAuthToken(String authToken) { mAccountManager.invalidateAuthToken(mAccount.type, authToken); } }
@Test public void invalidateAuthToken_noAccount() { am.invalidateAuthToken("type1", "token1"); }
public boolean reauth(AbstractAjaxCallback<?, ?> cb){ am.invalidateAuthToken(acc.type, token); try { token = am.blockingGetAuthToken(acc, type, true); AQUtility.debug("re token", token); } catch (Exception e) { AQUtility.debug(e); token = null; } return token != null; }
@Test public void invalidateAuthToken() throws Exception { mAuthenticator.invalidateAuthToken("monkey"); verify(mAccountManager).invalidateAuthToken("cooltype", "monkey"); }
@Test public void invalidateAuthToken() throws Exception { mAuthenticator.invalidateAuthToken("monkey"); verify(mAccountManager).invalidateAuthToken("cooltype", "monkey"); }
@Test public void invalidateAuthToken_noToken() { Account account1 = new Account("name", "type1"); shadowOf(am).addAccount(account1); am.invalidateAuthToken("type1", "token1"); }
@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(); }
public void invalidateUserToken(Context context, String token) { AccountManager accountManager = AccountManager.get(context); accountManager.invalidateAuthToken("com.google", token); }
@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_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(); }
public boolean invalidateToken(String token) { if (accountManager != null) { // USE_CREDENTIALS permission should be enough according to docs // but some systems require MANAGE_ACCOUNTS // java.lang.SecurityException: caller uid 10051 lacks android.permission.MANAGE_ACCOUNTS try { accountManager.invalidateAuthToken(GOOGLE_TYPE, token); return true; } catch (SecurityException e) { Log.w(TAG, e); } } return false; }
@Test public void shouldHandleSecurityExceptionWhenInvalidatingToken() throws Exception { doThrow(new SecurityException()).when(accountManager).invalidateAuthToken(GOOGLE_TYPE, "token"); assertThat(refresher.invalidateToken("token")).isFalse(); }
@Test public void shouldInvalidateTokenManually() throws Exception { assertThat(refresher.invalidateToken("token")).isTrue(); verify(accountManager).invalidateAuthToken(GOOGLE_TYPE, "token"); }
@Test public void shouldInvalidateTokenOnRefresh() throws Exception { when(authPreferences.getOauth2Token()).thenReturn("token"); when(authPreferences.getOauth2Username()).thenReturn("username"); when(accountManager.getAuthToken(notNull(Account.class), anyString(), isNull(Bundle.class), anyBoolean(), any(AccountManagerCallback.class), any(Handler.class))).thenReturn(mock(AccountManagerFuture.class)); try { refresher.refreshOAuth2Token(); fail("expected error "); } catch (TokenRefreshException e) { assertThat(e.getMessage()).isEqualTo("no bundle received from accountmanager"); } verify(accountManager).invalidateAuthToken(GOOGLE_TYPE, "token"); }
@Test public void shouldHandleExceptionsThrownByFuture() throws Exception { when(authPreferences.getOauth2Token()).thenReturn("token"); when(authPreferences.getOauth2Username()).thenReturn("username"); AccountManagerFuture<Bundle> future = mock(AccountManagerFuture.class); when(accountManager.getAuthToken(notNull(Account.class), anyString(), isNull(Bundle.class), anyBoolean(), any(AccountManagerCallback.class), any(Handler.class))).thenReturn(future); AuthenticatorException exception = new AuthenticatorException(); when(future.getResult()).thenThrow(exception); try { refresher.refreshOAuth2Token(); fail("expected exception"); } catch (TokenRefreshException e) { assertThat(e.getCause()).isSameAs(exception); } verify(accountManager).invalidateAuthToken(GOOGLE_TYPE, "token"); }
@Override public void invalidateAuthToken(String authToken) { mAccountManager.invalidateAuthToken(mAccount.type, authToken); } }
/** * Invalidates the given Google auth token by removing it from the account manager's cache (if * necessary) for example if the auth token has expired or otherwise become invalid. * * @param authToken auth token */ public void invalidateAuthToken(String authToken) { manager.invalidateAuthToken(ACCOUNT_TYPE, authToken); } }
@Override public void invalidateAuthToken(String authToken) { mAccountManager.invalidateAuthToken(mAccount.type, authToken); } }