Skip to content

Commit

Permalink
squash!
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolaRHristov committed Feb 14, 2024
1 parent cf7987b commit 40fa066
Show file tree
Hide file tree
Showing 32 changed files with 3,569 additions and 2,790 deletions.
98 changes: 49 additions & 49 deletions Source/authenticator.ts
Original file line number Diff line number Diff line change
@@ -1,55 +1,55 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { CancellationToken } from 'vscode';
import { SimpleFetch } from './common/request';
import { IAuthenticator } from './types';
import { generateNewApiToken, verifyApiToken } from './jupyterHubApi';
import type { CancellationToken } from "vscode";
import type { SimpleFetch } from "./common/request";
import { generateNewApiToken, verifyApiToken } from "./jupyterHubApi";
import type { IAuthenticator } from "./types";

export class Authenticator implements IAuthenticator {
constructor(private readonly fetch: SimpleFetch) {}
public async getJupyterAuthInfo(
options: {
baseUrl: string;
authInfo: {
username: string;
password: string;
token: string;
};
},
token: CancellationToken
): Promise<{ token: string; tokenId: string }> {
// Possible user has entered the API token instead of the password.
if (!options.authInfo.token) {
const isApiTokenValid = await verifyApiToken(
options.baseUrl,
options.authInfo.username,
options.authInfo.password,
this.fetch,
token
);
if (isApiTokenValid) {
return { tokenId: '', token: options.authInfo.password };
}
}
if (options.authInfo.token) {
const isApiTokenValid = await verifyApiToken(
options.baseUrl,
options.authInfo.username,
options.authInfo.token,
this.fetch,
token
);
if (isApiTokenValid) {
return { tokenId: '', token: options.authInfo.token };
}
}
return generateNewApiToken(
options.baseUrl,
options.authInfo.username,
options.authInfo.password,
this.fetch,
token
);
}
constructor(private readonly fetch: SimpleFetch) {}
public async getJupyterAuthInfo(
options: {
baseUrl: string;
authInfo: {
username: string;
password: string;
token: string;
};
},
token: CancellationToken,
): Promise<{ token: string; tokenId: string }> {
// Possible user has entered the API token instead of the password.
if (!options.authInfo.token) {
const isApiTokenValid = await verifyApiToken(
options.baseUrl,
options.authInfo.username,
options.authInfo.password,
this.fetch,
token,
);
if (isApiTokenValid) {
return { tokenId: "", token: options.authInfo.password };
}
}
if (options.authInfo.token) {
const isApiTokenValid = await verifyApiToken(
options.baseUrl,
options.authInfo.username,
options.authInfo.token,
this.fetch,
token,
);
if (isApiTokenValid) {
return { tokenId: "", token: options.authInfo.token };
}
}
return generateNewApiToken(
options.baseUrl,
options.authInfo.username,
options.authInfo.password,
this.fetch,
token,
);
}
}
Loading

0 comments on commit 40fa066

Please sign in to comment.