Search in sources :

Example 16 with GitHubClient

use of org.eclipse.egit.github.core.client.GitHubClient 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)

Aggregations

GitHubClient (org.eclipse.egit.github.core.client.GitHubClient)16 Intent (android.content.Intent)3 IOException (java.io.IOException)3 DataService (org.eclipse.egit.github.core.service.DataService)3 RepositoryService (org.eclipse.egit.github.core.service.RepositoryService)3 WatcherService (org.eclipse.egit.github.core.service.WatcherService)3 ArrayList (java.util.ArrayList)2 OAuthUserProvider (net.idlesoft.android.apps.github.authenticator.OAuthUserProvider)2 User (org.eclipse.egit.github.core.User)2 UserService (org.eclipse.egit.github.core.service.UserService)2 Account (android.accounts.Account)1 AccountsException (android.accounts.AccountsException)1 NetworkErrorException (android.accounts.NetworkErrorException)1 SharedPreferences (android.content.SharedPreferences)1 Rect (android.graphics.Rect)1 Drawable (android.graphics.drawable.Drawable)1 Bundle (android.os.Bundle)1 SparseBooleanArray (android.util.SparseBooleanArray)1 View (android.view.View)1 WebSettings (android.webkit.WebSettings)1