Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix authentication with remote kernels #2110

Merged
merged 3 commits into from
May 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions lib/ws-kernel-picker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import _ from "lodash";
import tildify from "tildify";
import { v4 } from "uuid";
import ws from "ws";
import { XMLHttpRequest as NodeXMLHttpRequest } from "@aminya/xmlhttprequest";
import { XMLHttpRequest as NodeXMLHttpRequest } from "xmlhttprequest"; // TODO use @aminya/xmlhttprequest
import { URL } from "url";
import { Kernel, Session, ServerConnection } from "@jupyterlab/services";
import Config from "./config";
Expand Down Expand Up @@ -149,7 +149,7 @@ export default class WSKernelPicker {
async promptForText(prompt: string) {
const previouslyFocusedElement = this.listView.previouslyFocusedElement;
this.listView.cancel();
const inputPromise = new Promise((resolve, reject) => {
const inputPromise = new Promise<string>((resolve, reject) => {
const inputView = new InputView(
{
prompt,
Expand All @@ -164,7 +164,7 @@ export default class WSKernelPicker {
});
inputView.attach();
});
let response;
let response: string | null | undefined = undefined;

try {
response = await inputPromise;
Expand All @@ -186,7 +186,7 @@ export default class WSKernelPicker {
async promptForCookie(options: DeepWriteable<KernelGatewayOptions>) {
const cookie = await this.promptForText("Cookie:");

if (cookie === null) {
if (cookie === null || cookie === undefined) {
return false;
}

Expand All @@ -203,7 +203,7 @@ export default class WSKernelPicker {
return request as XMLHttpRequest; // TODO fix the types
};

options.wsFactory = (url, protocol) => {
options.wsFactory = (url: string, protocol?: string | string[]) => {
// Authentication requires requests to appear to be same-origin
const parsedUrl = new URL(url);

Expand Down Expand Up @@ -260,18 +260,19 @@ export default class WSKernelPicker {
loadingMessage: null,
emptyMessage: null,
});
const action = await new Promise((resolve, reject) => {
this.listView.onConfirmed = (item) => resolve(item.action);
const action = await new Promise<string>((resolve, reject) => {
this.listView.onConfirmed = (item: { action: string }) =>
resolve(item.action);

this.listView.onCancelled = () => resolve("cancel");
});

if (action === "token") {
return await this.promptForToken(options);
return this.promptForToken(options);
}

if (action === "cookie") {
return await this.promptForCookie(options);
return this.promptForCookie(options);
}

// action === "cancel"
Expand All @@ -288,8 +289,9 @@ export default class WSKernelPicker {
emptyMessage: "No sessions available",
});
const gatewayOptions = {
xhrFactory: () => new NodeXMLHttpRequest() as XMLHttpRequest, // TODO fix the types
wsFactory: (url, protocol) => new ws(url, protocol),
xhrFactory: () => new XMLHttpRequest(),
wsFactory: (url: string, protocol?: string | string[]) =>
new ws(url, protocol),
...gatewayInfo.options,
};
let serverSettings = ServerConnection.makeSettings(gatewayOptions);
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"atom": ">=1.28.0 <2.0.0"
},
"dependencies": {
"@aminya/xmlhttprequest": "^1.8.2",
"@aminya/jmp": "^2.0.9",
"@babel/runtime-corejs2": "^7.0.0",
"@jupyterlab/services": "^0.52.0",
"@nteract/commutable": "^7.1.4",
Expand All @@ -70,7 +70,6 @@
"atom-select-list": "^0.7.0",
"escape-carriage": "^1.2.0",
"escape-string-regexp": "^4.0.0",
"@aminya/jmp": "^2.0.9",
"kernelspecs": "^2.0.0",
"lodash": "^4.14.0",
"mathjax-electron": "^3.0.0",
Expand All @@ -84,7 +83,8 @@
"styled-components": "^5.0.1",
"tildify": "^2.0.0",
"uuid": "^8.0.0",
"ws": "^7.0.0"
"ws": "^7.0.0",
"xmlhttprequest": "^1.8.0"
},
"consumedServices": {
"autocomplete.watchEditor": {
Expand Down