use of org.jetbrains.plugins.github.exceptions.GithubOperationCanceledException in project intellij-community by JetBrains.
the class GithubUtil method getValidAuthData.
private static void getValidAuthData(@NotNull final Project project, @NotNull final GithubAuthDataHolder authHolder, @NotNull final ProgressIndicator indicator, @NotNull final AuthLevel authLevel, @NotNull final GithubAuthData oldAuth) throws GithubOperationCanceledException {
authHolder.runTransaction(oldAuth, () -> {
final GithubAuthData[] authData = new GithubAuthData[1];
ApplicationManager.getApplication().invokeAndWait(() -> {
GithubLoginDialog dialog = new GithubLoginDialog(project, oldAuth, authLevel);
DialogManager.show(dialog);
if (dialog.isOK()) {
authData[0] = dialog.getAuthData();
if (!authLevel.isOnetime()) {
GithubSettings.getInstance().setAuthData(authData[0], dialog.isSavePasswordSelected());
}
}
}, indicator.getModalityState());
if (authData[0] == null)
throw new GithubOperationCanceledException("Can't get valid credentials");
return authData[0];
});
}
use of org.jetbrains.plugins.github.exceptions.GithubOperationCanceledException in project intellij-community by JetBrains.
the class GithubUtil method getTwoFactorAuthData.
private static void getTwoFactorAuthData(@NotNull final Project project, @NotNull final GithubAuthDataHolder authHolder, @NotNull final ProgressIndicator indicator, @NotNull final GithubAuthData oldAuth) throws GithubOperationCanceledException {
authHolder.runTransaction(oldAuth, () -> {
if (authHolder.getAuthData().getAuthType() != GithubAuthData.AuthType.BASIC) {
throw new GithubOperationCanceledException("Two factor authentication can be used only with Login/Password");
}
GithubApiUtil.askForTwoFactorCodeSMS(new GithubConnection(oldAuth, false));
final Ref<String> codeRef = new Ref<>();
ApplicationManager.getApplication().invokeAndWait(() -> {
codeRef.set(Messages.showInputDialog(project, "Authentication Code", "Github Two-Factor Authentication", null));
}, indicator.getModalityState());
if (codeRef.isNull()) {
throw new GithubOperationCanceledException("Can't get two factor authentication code");
}
GithubSettings settings = GithubSettings.getInstance();
if (settings.getAuthType() == GithubAuthData.AuthType.BASIC && StringUtil.equalsIgnoreCase(settings.getLogin(), oldAuth.getBasicAuth().getLogin())) {
settings.setValidGitAuth(false);
}
return oldAuth.copyWithTwoFactorCode(codeRef.get());
});
}
Aggregations