Skip to content

Commit

Permalink
Provide Device Flow as fallback when interactive login fails (#2521)
Browse files Browse the repository at this point in the history
* Provide Device Flow as fallback of interactive login.

* Hide Device Flow entry in sign-in window.

* Update release-note.

* Remove unused import.

* Remove an empty line.

* Remove an empty line.
  • Loading branch information
Eskibear authored Dec 14, 2018
1 parent f3eaf91 commit 7c4b646
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
<h3>[3.16.0]</h3>
<h4>Added</h4>
<ul>
<li>Support to sign in with OAuth 2.0 Device Flow. (Experimental)</li>
<li>Support both dedicated Azure explorer node and run configuration for Aris linked clusters.</li>
<li>Support Spark local run classpath modules selection.</li>
</ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,34 @@
public class ErrorWindow extends AzureDialogWrapper {
private JPanel contentPane;
private JTextPane textPane;
private Runnable okAction;

public static void show(@Nullable Project project, String message, String title) {
ErrorWindow w = new ErrorWindow(project, message, title);
show(project, message, title, null, null);
}

public static void show(@Nullable Project project, String message, String title, String okButtonText, Runnable okAction){
ErrorWindow w = new ErrorWindow(project, message, title, okButtonText, okAction);
w.show();

}

protected ErrorWindow(@Nullable Project project, String message, String title) {
protected ErrorWindow(@Nullable Project project, String message, String title){
this(project, message, title, null, null);
}

protected ErrorWindow(@Nullable Project project, String message, String title, String okButtonText, Runnable okAction) {
super(project, true, IdeModalityType.PROJECT);
setModal(true);
if (title != null && !title.isEmpty()) {
setTitle(title);
} else {
setTitle("Error Notification");
}

if (okButtonText != null) {
setOKButtonText(okButtonText);
this.okAction = okAction;
}
setCancelButtonText("Close");
textPane.setText(message);

Expand All @@ -64,12 +77,20 @@ protected JComponent createCenterPanel() {

@Override
protected Action[] createActions() {
return new Action[]{this.getCancelAction()};
return new Action[]{this.getCancelAction(), this.okAction != null ? this.getOKAction() : null};
}

@Nullable
@Override
protected String getDimensionServiceKey() {
return "ErrorWindow";
}

@Override
protected void doOKAction() {
super.doOKAction();
if (this.okAction != null) {
this.okAction.run();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,20 @@
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<enabled value="false"/>
<selected value="false"/>
<text value="Device Flow (Experimental)"/>
<visible value="false"/>
</properties>
</component>
<grid id="f334d" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="3" use-parent-layout="false"/>
</constraints>
<properties/>
<properties>
<enabled value="false"/>
</properties>
<border type="none"/>
<children>
<component id="15e3b" class="javax.swing.JLabel" binding="deviceLoginCommentLabel">
Expand All @@ -108,6 +112,7 @@
</constraints>
<properties>
<text value="You will need to open an external browser and sign in with a generated device code."/>
<visible value="false"/>
</properties>
</component>
</children>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,17 @@ public void run(ProgressIndicator indicator) {
ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override
public void run() {
ErrorWindow.show(project, ex.getMessage(), SIGN_IN_ERROR);
// To revert after Device Flow is stable.
ErrorWindow.show(project, ex.getMessage(), SIGN_IN_ERROR, "Try Device Flow", () -> {
authMethodDetailsResult = new AuthMethodDetails();
doDeviceLogin();
if (!StringUtils.isNullOrEmpty(accountEmail)) {
authMethodDetailsResult.setAuthMethod(AuthMethod.DC);
authMethodDetailsResult.setAccountEmail(accountEmail);
authMethodDetailsResult.setAzureEnv(CommonSettings.getEnvironment().getName());
SignInWindow.super.doOKAction();
}
});
}
});
}
Expand Down

0 comments on commit 7c4b646

Please sign in to comment.