forked from microsoft/vscode-jupyter-hub
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cf7987b
commit 40fa066
Showing
32 changed files
with
3,569 additions
and
2,790 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
); | ||
} | ||
} |
Oops, something went wrong.