Search in sources :

Example 1 with GithubTwoFactorAuthenticationException

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

the class GithubUtil method testConnection.

@NotNull
private static GithubUserDetailed testConnection(@NotNull Project project, @NotNull GithubAuthDataHolder authHolder, @NotNull final ProgressIndicator indicator) throws IOException {
    GithubAuthData auth = authHolder.getAuthData();
    try {
        final GithubConnection connection = new GithubConnection(auth, true);
        ScheduledFuture<?> future = null;
        try {
            future = addCancellationListener(indicator, connection);
            return GithubApiUtil.getCurrentUser(connection);
        } finally {
            connection.close();
            if (future != null)
                future.cancel(true);
        }
    } catch (GithubTwoFactorAuthenticationException e) {
        getTwoFactorAuthData(project, authHolder, indicator, auth);
        return testConnection(project, authHolder, indicator);
    }
}
Also used : GithubConnection(org.jetbrains.plugins.github.api.GithubConnection) GithubTwoFactorAuthenticationException(org.jetbrains.plugins.github.exceptions.GithubTwoFactorAuthenticationException) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with GithubTwoFactorAuthenticationException

use of org.jetbrains.plugins.github.exceptions.GithubTwoFactorAuthenticationException 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)

Aggregations

GithubConnection (org.jetbrains.plugins.github.api.GithubConnection)2 GithubTwoFactorAuthenticationException (org.jetbrains.plugins.github.exceptions.GithubTwoFactorAuthenticationException)2 NotNull (org.jetbrains.annotations.NotNull)1 GithubAuthenticationException (org.jetbrains.plugins.github.exceptions.GithubAuthenticationException)1