mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-01-21 08:20:20 +00:00
Change websocket authentication from url token to getting token from payload (#1487)
* Change websocket authentication from url to message body * Add new message type * Validation checks * Remove flight and always send token in payload
This commit is contained in:
parent
1d6c0bbd1e
commit
cf0c51337f
@ -1,23 +1,23 @@
|
||||
import {
|
||||
actions,
|
||||
AppState,
|
||||
castToSessionId,
|
||||
ContentRef,
|
||||
createKernelRef,
|
||||
JupyterHostRecordProps,
|
||||
ServerConfig as JupyterServerConfig,
|
||||
KernelInfo,
|
||||
KernelRef,
|
||||
RemoteKernelProps,
|
||||
actions,
|
||||
castToSessionId,
|
||||
createKernelRef,
|
||||
selectors,
|
||||
ServerConfig as JupyterServerConfig,
|
||||
} from "@nteract/core";
|
||||
import { Channels, childOf, createMessage, JupyterMessage, message, ofMessageType } from "@nteract/messaging";
|
||||
import { Channels, childOf, createMessage, message, ofMessageType } from "@nteract/messaging";
|
||||
import { defineConfigOption } from "@nteract/mythic-configuration";
|
||||
import { RecordOf } from "immutable";
|
||||
import { Action, AnyAction } from "redux";
|
||||
import { ofType, StateObservable } from "redux-observable";
|
||||
import { StateObservable, ofType } from "redux-observable";
|
||||
import { kernels, sessions } from "rx-jupyter";
|
||||
import { concat, EMPTY, from, interval, merge, Observable, Observer, of, Subject, Subscriber, timer } from "rxjs";
|
||||
import { EMPTY, Observable, Observer, Subject, Subscriber, concat, from, interval, merge, of, timer } from "rxjs";
|
||||
import {
|
||||
catchError,
|
||||
concatMap,
|
||||
@ -35,17 +35,17 @@ import {
|
||||
import { webSocket } from "rxjs/webSocket";
|
||||
import * as Constants from "../../../Common/Constants";
|
||||
import { Areas } from "../../../Common/Constants";
|
||||
import { useTabs } from "../../../hooks/useTabs";
|
||||
import { Action as TelemetryAction, ActionModifiers } from "../../../Shared/Telemetry/TelemetryConstants";
|
||||
import { ActionModifiers, Action as TelemetryAction } from "../../../Shared/Telemetry/TelemetryConstants";
|
||||
import * as TelemetryProcessor from "../../../Shared/Telemetry/TelemetryProcessor";
|
||||
import { logConsoleError, logConsoleInfo } from "../../../Utils/NotificationConsoleUtils";
|
||||
import { useTabs } from "../../../hooks/useTabs";
|
||||
import { useDialog } from "../../Controls/Dialog";
|
||||
import * as FileSystemUtil from "../FileSystemUtil";
|
||||
import * as cdbActions from "../NotebookComponent/actions";
|
||||
import { NotebookContentProviderType, NotebookUtil } from "../NotebookUtil";
|
||||
import * as CdbActions from "./actions";
|
||||
import * as TextFile from "./contents/file/text-file";
|
||||
import { CdbAppState } from "./types";
|
||||
import { CdbAppState, JupyterMessage } from "./types";
|
||||
|
||||
interface NotebookServiceConfig extends JupyterServerConfig {
|
||||
userPuid?: string;
|
||||
@ -106,10 +106,8 @@ const formWebSocketURL = (serverConfig: NotebookServiceConfig, kernelId: string,
|
||||
if (sessionId) {
|
||||
params.append("session_id", sessionId);
|
||||
}
|
||||
|
||||
const q = params.toString();
|
||||
const suffix = q !== "" ? `?${q}` : "";
|
||||
|
||||
const url = (serverConfig.endpoint.slice(0, -1) || "") + `api/kernels/${kernelId}/channels${suffix}`;
|
||||
|
||||
return url.replace(/^http(s)?/, "ws$1");
|
||||
@ -241,10 +239,10 @@ const connect = (serverConfig: NotebookServiceConfig, kernelID: string, sessionI
|
||||
...message,
|
||||
header: {
|
||||
session: sessionID,
|
||||
token: serverConfig.token,
|
||||
...message.header,
|
||||
},
|
||||
};
|
||||
|
||||
wsSubject.next(sessionizedMessage);
|
||||
} else {
|
||||
console.error("Message must be an object, the app sent", message);
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { CellId } from "@nteract/commutable";
|
||||
import { AppState } from "@nteract/core";
|
||||
import { MessageType } from "@nteract/messaging";
|
||||
import * as Immutable from "immutable";
|
||||
import { Notebook } from "../../../Common/Constants";
|
||||
|
||||
@ -53,3 +54,26 @@ export const makeCdbRecord = Immutable.Record<CdbRecordProps>({
|
||||
pendingSnapshotRequest: undefined,
|
||||
notebookSnapshotError: undefined,
|
||||
});
|
||||
|
||||
export interface JupyterMessage<MT extends MessageType = MessageType, C = any> {
|
||||
header: JupyterMessageHeader<MT>;
|
||||
parent_header:
|
||||
| JupyterMessageHeader<any>
|
||||
| {
|
||||
msg_id?: string;
|
||||
};
|
||||
metadata: object;
|
||||
content: C;
|
||||
channel: string;
|
||||
buffers?: Uint8Array | null;
|
||||
}
|
||||
|
||||
export interface JupyterMessageHeader<MT extends MessageType = MessageType> {
|
||||
msg_id: string;
|
||||
username: string;
|
||||
date: string;
|
||||
msg_type: MT;
|
||||
version: string;
|
||||
session: string;
|
||||
token: string;
|
||||
}
|
||||
|
@ -47,6 +47,10 @@ export class JupyterLabAppFactory {
|
||||
}
|
||||
|
||||
public async createTerminalApp(serverSettings: ServerConnection.ISettings): Promise<ITerminalConnection | undefined> {
|
||||
//Need to add this after we remove passing token through url
|
||||
//const configurationSettings: Partial<ServerConnection.ISettings> = serverSettings;
|
||||
//(configurationSettings.appendToken as boolean) = false;
|
||||
//serverSettings = ServerConnection.makeSettings(configurationSettings);
|
||||
const manager = new TerminalManager({
|
||||
serverSettings: serverSettings,
|
||||
});
|
||||
@ -64,6 +68,11 @@ export class JupyterLabAppFactory {
|
||||
}
|
||||
}, this);
|
||||
|
||||
let internalSend = session.send;
|
||||
session.send = (message: IMessage) => {
|
||||
message?.content?.push(serverSettings?.token);
|
||||
internalSend.call(session, message);
|
||||
};
|
||||
const term = new Terminal(session, { theme: "dark", shutdownOnClose: true });
|
||||
|
||||
if (!term) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user