Search in sources :

Example 1 with GithubOperationCanceledException

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];
    });
}
Also used : GithubOperationCanceledException(org.jetbrains.plugins.github.exceptions.GithubOperationCanceledException) GithubLoginDialog(org.jetbrains.plugins.github.ui.GithubLoginDialog)

Example 2 with GithubOperationCanceledException

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());
    });
}
Also used : GithubConnection(org.jetbrains.plugins.github.api.GithubConnection) Ref(com.intellij.openapi.util.Ref) GithubOperationCanceledException(org.jetbrains.plugins.github.exceptions.GithubOperationCanceledException)

Aggregations

GithubOperationCanceledException (org.jetbrains.plugins.github.exceptions.GithubOperationCanceledException)2 Ref (com.intellij.openapi.util.Ref)1 GithubConnection (org.jetbrains.plugins.github.api.GithubConnection)1 GithubLoginDialog (org.jetbrains.plugins.github.ui.GithubLoginDialog)1