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