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
Ability to update authorization token in documentManager after creation #12802
Comments
Thank you for opening your first issue in this project! Engagement like this is essential for open source projects! 🤗 |
If it's at all possible, even just making the serverSettings.token not readonly would fix this issue. |
this would be very helpful to me as well. @IngeCeux have you found any workaround to this ? Thanks! |
I created a fork of the repo and removed the 'readonly' from the token in |
ah I see, yeah that would be nice to have on upstream as well. I found a different workaround that seems to be working fine in my initial tests: I basically extended the ServerConnection.makeSettings function to inject my own implementation of websockets + fetch import { ServerConnection } from '@jupyterlab/services';
let changingToken = "token";
function fetchWithToken(input: RequestInfo, init?: RequestInit) {
if (!init) {
init = {};
}
if (!init.headers) {
init.headers = new Headers();
}
const bearer = `Bearer ${changingToken}`;
if (init.headers instanceof Headers) {
init.headers.append('Authorization', bearer);
} else if (init.headers instanceof Array) {
init.headers.push(['Authorization', bearer]);
} else {
init.headers['Authorization'] = bearer;
}
return window.fetch(input, init);
}
class WebSocketWithToken extends window.WebSocket {
constructor(url: string | URL) {
super(`${url}&jwtToken=${changingToken}`);
}
}
const originalMakeSettings = ServerConnection['makeSettings'];
ServerConnection['makeSettings'] = function makeSettings(
options?: Partial<ServerConnection.ISettings>
): ServerConnection.ISettings {
return originalMakeSettings({
...options,
WebSocket: WebSocketWithToken,
fetch: fetchWithToken
});
};
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
/**
* Initialization data for the cloud-integration extension.
*/
const plugin: JupyterFrontEndPlugin<void> = {
id: 'cloud-integration:plugin', |
Problem
I'm currently building a frontend in Angular using JupyterLab components (NotebookPanel). We use an extended Jupyter Server instance that uses authorization tokens which refresh every so often. To account for this, I now set the token in the PageConfig upon loading the app, and update it every time the token is refreshed. I've noticed, however, that once I've created the DocumentManager to handle the Widget creation and communication with the backend (api calls like /sessions, /kernels, /content,...), the token is not updated since the initial creation. So the Authorization header in the api calls stays the same and gives me a 401 Unauthorized response once the token is no longer valid.
Proposed Solution
I need a way to update this token in an existing DocumentManager serverSettings, which will then automatically update the serverSettings.token in all the children (ServiceManager>SessionManager, ContentsManager, KernelManager,...). Maybe a simple method refreshToken(token) in the docManager will do?
The text was updated successfully, but these errors were encountered: