import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
+import java.lang.reflect.Array;
import java.net.URLEncoder;
import java.util.*;
import java.util.List;
@NotNull
public static String getMasterToken(@NotNull GithubAuthData auth, @Nullable String note) throws IOException {
- List<String> scopes = new ArrayList<String>();
-
- scopes.add("repo"); // read/write access to public/private repositories
- scopes.add("gist"); // create/delete gists
+ // "repo" - read/write access to public/private repositories
+ // "gist" - create/delete gists
+ List<String> scopes = Arrays.asList("repo", "gist");
return getScopedToken(auth, scopes, note);
}
+++ /dev/null
-/*
- * Copyright 2000-2013 JetBrains s.r.o.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jetbrains.plugins.github.ui;
-
-import com.intellij.openapi.diagnostic.Logger;
-import com.intellij.openapi.project.Project;
-import com.intellij.openapi.ui.DialogWrapper;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.plugins.github.util.GithubSettings;
-import org.jetbrains.plugins.github.util.GithubUtil;
-
-import javax.swing.*;
-
-/**
- * @author oleg
- * @date 10/20/10
- */
-public class GithubTwoFactorDialog extends DialogWrapper {
-
- protected static final Logger LOG = GithubUtil.LOG;
-
- protected final GithubTwoFactorPanel myGithubTwoFactorPanel;
- protected final GithubSettings mySettings;
-
- public GithubTwoFactorDialog(@NotNull final Project project) {
- super(project, false);
-
- myGithubTwoFactorPanel = new GithubTwoFactorPanel();
-
- mySettings = GithubSettings.getInstance();
-
- setTitle("Github Two-Factor Authentication");
- setOKButtonText("Verify");
- init();
- }
-
- @NotNull
- protected Action[] createActions() {
- return new Action[]{getOKAction(), getCancelAction(), getHelpAction()};
- }
-
- @Override
- protected JComponent createCenterPanel() {
- return myGithubTwoFactorPanel.getPanel();
- }
-
- @Override
- protected String getHelpId() {
- return "github.two.factor.dialog";
- }
-
- @Override
- protected String getDimensionServiceKey() {
- return "Github.TwoFactorDialog";
- }
-
- @Override
- public JComponent getPreferredFocusedComponent() {
- return myGithubTwoFactorPanel.getPreferableFocusComponent();
- }
-
- @Override
- protected void doOKAction() {
- super.doOKAction();
- }
-
- @NotNull
- public String getCode() {
- return myGithubTwoFactorPanel.getCode();
- }
-}
\ No newline at end of file
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="org.jetbrains.plugins.github.ui.GithubTwoFactorPanel">
- <grid id="27dc6" binding="myPane" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
- <margin top="0" left="0" bottom="0" right="0"/>
- <constraints>
- <xy x="20" y="20" width="500" height="174"/>
- </constraints>
- <properties>
- <focusable value="false"/>
- </properties>
- <border type="none"/>
- <children>
- <vspacer id="9b306">
- <constraints>
- <grid row="1" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
- </constraints>
- </vspacer>
- <component id="dbea1" class="javax.swing.JLabel">
- <constraints>
- <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
- </constraints>
- <properties>
- <text value="Authentication Code:"/>
- </properties>
- </component>
- <component id="f5630" class="javax.swing.JTextField" binding="myCodeTextField">
- <constraints>
- <grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
- <preferred-size width="150" height="-1"/>
- </grid>
- </constraints>
- <properties/>
- </component>
- </children>
- </grid>
-</form>
+++ /dev/null
-/*
- * Copyright 2000-2013 JetBrains s.r.o.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jetbrains.plugins.github.ui;
-
-import org.jetbrains.annotations.NotNull;
-
-import javax.swing.*;
-
-/**
- * @author oleg
- * @date 10/20/10
- */
-public class GithubTwoFactorPanel {
- private JPanel myPane;
- private JTextField myCodeTextField;
-
- public GithubTwoFactorPanel() {
- }
-
- public JComponent getPanel() {
- return myPane;
- }
-
- @NotNull
- public String getCode() {
- return myCodeTextField.getText().trim();
- }
-
- public JComponent getPreferableFocusComponent() {
- return myCodeTextField;
- }
-}
-
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.progress.Task;
import com.intellij.openapi.project.Project;
+import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.ThrowableComputable;
import com.intellij.openapi.util.text.StringUtil;
import org.jetbrains.plugins.github.exceptions.GithubTwoFactorAuthenticationException;
import org.jetbrains.plugins.github.ui.GithubBasicLoginDialog;
import org.jetbrains.plugins.github.ui.GithubLoginDialog;
-import org.jetbrains.plugins.github.ui.GithubTwoFactorDialog;
import java.io.IOException;
import java.net.UnknownHostException;
GithubApiUtil.askForTwoFactorCodeSMS(oldAuth);
- final GithubTwoFactorDialog dialog = new GithubTwoFactorDialog(project);
+ final AtomicReference<String> codeRef = new AtomicReference<String>();
ApplicationManager.getApplication().invokeAndWait(new Runnable() {
@Override
public void run() {
- DialogManager.show(dialog);
+ codeRef.set(Messages.showInputDialog(project, "Authentication Code", "Github Two-Factor Authentication", null));
}
}, indicator.getModalityState());
- if (!dialog.isOK()) {
+ if (codeRef.get() == null) {
throw new GithubOperationCanceledException("Can't get two factor authentication code");
}
- return oldAuth.copyWithTwoFactorCode(dialog.getCode());
+ return oldAuth.copyWithTwoFactorCode(codeRef.get());
}
});
}
}
public void testWrongLogin() throws Throwable {
- registerDefaultLoginDialogHandler();
+ registerCancelingLoginDialogHandler();
List<FileContent> expected = createContent();
}
public void testWrongPassword() throws Throwable {
- registerDefaultLoginDialogHandler();
+ registerCancelingLoginDialogHandler();
List<FileContent> expected = createContent();
assertTrue("Gist content differs from sample", Comparing.haveEqualElements(expected, actual));
}
- protected void registerDefaultLoginDialogHandler() {
+ protected void registerCancelingLoginDialogHandler() {
myDialogManager.registerDialogHandler(GithubLoginDialog.class, new TestDialogHandler<GithubLoginDialog>() {
@Override
public int handleDialog(GithubLoginDialog dialog) {