Search in sources :

Example 1 with GithubAuthenticationException

use of org.jetbrains.plugins.github.exceptions.GithubAuthenticationException in project intellij-community by JetBrains.

the class GithubCredentialsPanel method testAuthData.

private void testAuthData(@NotNull Project project) {
    try {
        GithubAuthData auth = getAuthData();
        GithubUser user = GithubUtil.computeValueInModalIO(project, "Access to GitHub", indicator -> GithubUtil.checkAuthData(project, new GithubAuthDataHolder(auth), indicator));
        if (AuthType.TOKEN.equals(auth.getAuthType())) {
            GithubNotifications.showInfoDialog(myPane, "Success", "Connection successful for user " + user.getLogin());
        } else {
            GithubNotifications.showInfoDialog(myPane, "Success", "Connection successful");
        }
    } catch (GithubAuthenticationException ex) {
        GithubNotifications.showErrorDialog(myPane, "Login Failure", "Can't login using given credentials: ", ex);
    } catch (IOException ex) {
        GithubNotifications.showErrorDialog(myPane, "Login Failure", "Can't login: ", ex);
    }
}
Also used : GithubAuthenticationException(org.jetbrains.plugins.github.exceptions.GithubAuthenticationException) GithubUser(org.jetbrains.plugins.github.api.data.GithubUser) IOException(java.io.IOException)

Example 2 with GithubAuthenticationException

use of org.jetbrains.plugins.github.exceptions.GithubAuthenticationException in project intellij-community by JetBrains.

the class GithubUtil method runTask.

public static <T> T runTask(@NotNull Project project, @NotNull GithubAuthDataHolder authHolder, @NotNull final ProgressIndicator indicator, @NotNull AuthLevel authLevel, @NotNull ThrowableConvertor<GithubConnection, T, IOException> task) throws IOException {
    GithubAuthData auth = authHolder.getAuthData();
    try {
        if (!authLevel.accepts(auth)) {
            throw new GithubAuthenticationException("Expected other authentication type: " + authLevel);
        }
        final GithubConnection connection = new GithubConnection(auth, true);
        ScheduledFuture<?> future = null;
        try {
            future = addCancellationListener(indicator, connection);
            return task.convert(connection);
        } finally {
            connection.close();
            if (future != null)
                future.cancel(true);
        }
    } catch (GithubTwoFactorAuthenticationException e) {
        getTwoFactorAuthData(project, authHolder, indicator, auth);
        return runTask(project, authHolder, indicator, authLevel, task);
    } catch (GithubAuthenticationException e) {
        getValidAuthData(project, authHolder, indicator, authLevel, auth);
        return runTask(project, authHolder, indicator, authLevel, task);
    }
}
Also used : GithubConnection(org.jetbrains.plugins.github.api.GithubConnection) GithubAuthenticationException(org.jetbrains.plugins.github.exceptions.GithubAuthenticationException) GithubTwoFactorAuthenticationException(org.jetbrains.plugins.github.exceptions.GithubTwoFactorAuthenticationException)

Example 3 with GithubAuthenticationException

use of org.jetbrains.plugins.github.exceptions.GithubAuthenticationException in project intellij-community by JetBrains.

the class GithubUtil method getValidAuthDataHolderFromConfig.

@NotNull
public static GithubAuthDataHolder getValidAuthDataHolderFromConfig(@NotNull Project project, @NotNull AuthLevel authLevel, @NotNull ProgressIndicator indicator) throws IOException {
    GithubAuthData auth = GithubAuthData.createFromSettings();
    GithubAuthDataHolder authHolder = new GithubAuthDataHolder(auth);
    try {
        if (!authLevel.accepts(auth))
            throw new GithubAuthenticationException("Expected other authentication type: " + authLevel);
        checkAuthData(project, authHolder, indicator);
        return authHolder;
    } catch (GithubAuthenticationException e) {
        getValidAuthData(project, authHolder, indicator, authLevel, auth);
        return authHolder;
    }
}
Also used : GithubAuthenticationException(org.jetbrains.plugins.github.exceptions.GithubAuthenticationException) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

GithubAuthenticationException (org.jetbrains.plugins.github.exceptions.GithubAuthenticationException)3 IOException (java.io.IOException)1 NotNull (org.jetbrains.annotations.NotNull)1 GithubConnection (org.jetbrains.plugins.github.api.GithubConnection)1 GithubUser (org.jetbrains.plugins.github.api.data.GithubUser)1 GithubTwoFactorAuthenticationException (org.jetbrains.plugins.github.exceptions.GithubTwoFactorAuthenticationException)1