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