Search in sources :

Example 1 with NetworkErrorException

use of android.accounts.NetworkErrorException in project 360-Engine-for-Android by 360.

the class AuthenticatorTest method testGetAccountRemovalAllowed.

/***
     * Test the getAccountRemovalAllowed() method.
     */
@SmallTest
@Suppress
public final void testGetAccountRemovalAllowed() {
    final TestStatus testStatus = new TestStatus();
    Authenticator authenticator = new Authenticator(getContext(), new MainApplication() {

        public void removeUserData() {
            /*
                 * Test that the dummy mWakeListener.notifyOfWakeupAlarm() has
                 * been called, otherwise the test must fail.
                 */
            testStatus.setPass(true);
        }
    });
    Bundle bundle = null;
    try {
        bundle = authenticator.getAccountRemovalAllowed(null, null);
    } catch (NetworkErrorException e) {
        fail("Unexpected NetworkErrorException");
    }
    /** Test if removeUserData() was called. **/
    assertTrue("Expecting the removeUserData() dummy method to have " + "been called", testStatus.isPass());
    assertEquals("Expected a KEY_BOOLEAN_RESULT boolean", true, bundle.getBoolean(AccountManager.KEY_BOOLEAN_RESULT));
}
Also used : NetworkErrorException(android.accounts.NetworkErrorException) TestStatus(com.vodafone360.people.tests.testutils.TestStatus) Bundle(android.os.Bundle) Authenticator(com.vodafone360.people.service.Authenticator) MainApplication(com.vodafone360.people.MainApplication) SmallTest(android.test.suitebuilder.annotation.SmallTest) Suppress(android.test.suitebuilder.annotation.Suppress)

Example 2 with NetworkErrorException

use of android.accounts.NetworkErrorException in project hubroid by EddieRingle.

the class GitHubAccountAuthenticator method getAuthToken.

@Override
public Bundle getAuthToken(AccountAuthenticatorResponse response, Account account, String authTokenType, Bundle options) throws NetworkErrorException {
    String password = AccountManager.get(mContext).getPassword(account);
    Authorization auth = null;
    try {
        GitHubClient client = new GitHubClient();
        client.setUserAgent(USER_AGENT_STRING);
        client.setCredentials(account.name, password);
        OAuthService service = new OAuthService(client);
        for (Authorization a : service.getAuthorizations()) {
            if (a != null && a.getNote() != null) {
                if (a.getNote().equals(DESCRIPTION_CLIENT)) {
                    auth = a;
                }
            }
        }
        if (auth == null) {
            auth = new Authorization();
            auth.setNote(DESCRIPTION_CLIENT);
            auth.setNoteUrl(CLIENT_URL);
            List<String> scopes = new ArrayList<String>();
            scopes.add("user");
            scopes.add("repo");
            scopes.add("gist");
            auth.setScopes(scopes);
            auth = service.createAuthorization(auth);
        }
    } catch (IOException e) {
        throw new NetworkErrorException(e);
    }
    String oauthToken = auth.getToken();
    Bundle bundle = new Bundle();
    bundle.putString(KEY_ACCOUNT_NAME, account.name);
    bundle.putString(KEY_ACCOUNT_TYPE, GITHUB_ACCOUNT_TYPE);
    bundle.putString(KEY_AUTHTOKEN, oauthToken);
    return bundle;
}
Also used : Authorization(org.eclipse.egit.github.core.Authorization) NetworkErrorException(android.accounts.NetworkErrorException) GitHubClient(org.eclipse.egit.github.core.client.GitHubClient) OAuthService(org.eclipse.egit.github.core.service.OAuthService) Bundle(android.os.Bundle) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Example 3 with NetworkErrorException

use of android.accounts.NetworkErrorException in project apps-android-commons by commons-app.

the class WikiAccountAuthenticator method getAuthToken.

@Override
public Bundle getAuthToken(AccountAuthenticatorResponse response, Account account, String authTokenType, Bundle options) throws NetworkErrorException {
    // Extract the username and password from the Account Manager, and ask
    // the server for an appropriate AuthToken.
    final AccountManager am = AccountManager.get(context);
    final String password = am.getPassword(account);
    if (password != null) {
        String authCookie;
        try {
            authCookie = getAuthCookie(account.name, password);
        } catch (IOException e) {
            // Network error!
            e.printStackTrace();
            throw new NetworkErrorException(e);
        }
        if (authCookie != null) {
            final Bundle result = new Bundle();
            result.putString(AccountManager.KEY_ACCOUNT_NAME, account.name);
            result.putString(AccountManager.KEY_ACCOUNT_TYPE, AccountUtil.accountType());
            result.putString(AccountManager.KEY_AUTHTOKEN, authCookie);
            return result;
        }
    }
    // If we get here, then we couldn't access the user's password - so we
    // need to re-prompt them for their credentials. We do that by creating
    // an intent to display our AuthenticatorActivity panel.
    final Intent intent = new Intent(context, LoginActivity.class);
    intent.putExtra(LoginActivity.PARAM_USERNAME, account.name);
    intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response);
    final Bundle bundle = new Bundle();
    bundle.putParcelable(AccountManager.KEY_INTENT, intent);
    return bundle;
}
Also used : NetworkErrorException(android.accounts.NetworkErrorException) Bundle(android.os.Bundle) AccountManager(android.accounts.AccountManager) Intent(android.content.Intent) IOException(java.io.IOException)

Aggregations

NetworkErrorException (android.accounts.NetworkErrorException)3 Bundle (android.os.Bundle)3 IOException (java.io.IOException)2 AccountManager (android.accounts.AccountManager)1 Intent (android.content.Intent)1 SmallTest (android.test.suitebuilder.annotation.SmallTest)1 Suppress (android.test.suitebuilder.annotation.Suppress)1 MainApplication (com.vodafone360.people.MainApplication)1 Authenticator (com.vodafone360.people.service.Authenticator)1 TestStatus (com.vodafone360.people.tests.testutils.TestStatus)1 ArrayList (java.util.ArrayList)1 Authorization (org.eclipse.egit.github.core.Authorization)1 GitHubClient (org.eclipse.egit.github.core.client.GitHubClient)1 OAuthService (org.eclipse.egit.github.core.service.OAuthService)1