use of org.eclipse.egit.github.core.Authorization 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;
}
Aggregations