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));
}
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;
}
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;
}
Aggregations