Skip to content

Commit

Permalink
Use proxyURL to log into sandbox using Red Hat auth token
Browse files Browse the repository at this point in the history
Fix #2519.

Signed-off-by: Denis Golovin [email protected]
  • Loading branch information
dgolovin committed Mar 23, 2023
1 parent 97f23a5 commit 88c5cf7
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 15 deletions.
18 changes: 9 additions & 9 deletions src/openshift/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -451,15 +451,15 @@ export class Cluster extends OpenShiftItem {
@vsCommand('openshift.explorer.login.clipboard')
static async loginUsingClipboardToken(apiEndpointUrl: string, oauthRequestTokenUrl: string): Promise<string | null> {
const clipboard = await Cluster.readFromClipboard();
if(!clipboard) {
const choice = await window.showErrorMessage('Cannot parse token in clipboard. Please click `Get token` button below, copy token into clipboard and press `Login to Sandbox` button again.',
'Get token');
if (choice === 'Get token') {
await commands.executeCommand('vscode.open', Uri.parse(oauthRequestTokenUrl));
}
return;
}
return Cluster.tokenLogin(apiEndpointUrl, true, clipboard);
// if(!clipboard) {
// const choice = await window.showErrorMessage('Cannot parse token in clipboard. Please click `Get token` button below, copy token into clipboard and press `Login to Sandbox` button again.',
// 'Get token');
// if (choice === 'Get token') {
// await commands.executeCommand('vscode.open', Uri.parse(oauthRequestTokenUrl));
// }
// return;
// }
return Cluster.tokenLogin(apiEndpointUrl, true, oauthRequestTokenUrl);
}

static async loginUsingClipboardInfo(dashboardUrl: string): Promise<string | null> {
Expand Down
1 change: 1 addition & 0 deletions src/openshift/sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export interface SBSignupResponse {
givenName: string;
status: SBStatus;
username: string;
proxyURL: string;
}

export interface SBResponseData {
Expand Down
11 changes: 7 additions & 4 deletions src/webview/cluster/app/sandboxView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ export default function addSandboxView(props): JSX.Element {
consoleDashboard: '',
apiEndpoint: '',
oauthTokenEndpoint: '',
errorCode: undefined
errorCode: undefined,
proxyUrl: ''
});

const messageListener = (event) => {
Expand Down Expand Up @@ -151,7 +152,8 @@ export default function addSandboxView(props): JSX.Element {
statusInfo: currentState.statusInfo,
apiEndpoint: '',
oauthTokenEndpoint: '',
errorCode: undefined
errorCode: undefined,
proxyUrl: ''
});
postMessage('sandboxDetectStatus');
}
Expand Down Expand Up @@ -302,7 +304,8 @@ export default function addSandboxView(props): JSX.Element {
consoleDashboard: '',
apiEndpoint: '',
oauthTokenEndpoint: '',
errorCode: undefined
errorCode: undefined,
proxyUrl: ''
});
}

Expand Down Expand Up @@ -379,7 +382,7 @@ export default function addSandboxView(props): JSX.Element {
const Provisioned = () => {

const handleLoginButton = () => {
postMessage('sandboxLoginUsingDataInClipboard', {apiEndpointUrl: currentState.apiEndpoint, oauthRequestTokenUrl: `${currentState.oauthTokenEndpoint}/request`});
postMessage('sandboxLoginUsingDataInClipboard', {apiEndpointUrl: currentState.apiEndpoint, oauthRequestTokenUrl: `${currentState.oauthTokenEndpoint}/request`, proxyUrl: currentState.proxyUrl});
};

return (
Expand Down
4 changes: 2 additions & 2 deletions src/webview/cluster/clusterViewLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ async function clusterEditorMessageListener (event: any ): Promise<any> {
} else {
if (signupStatus.status.ready) {
const oauthInfo = await sandboxAPI.getOauthServerInfo(signupStatus.apiEndpoint);
panel.webview.postMessage({action: 'sandboxPageProvisioned', statusInfo: signupStatus.username, consoleDashboard: signupStatus.consoleURL, apiEndpoint: signupStatus.apiEndpoint, oauthTokenEndpoint: oauthInfo.token_endpoint });
panel.webview.postMessage({action: 'sandboxPageProvisioned', statusInfo: signupStatus.username, consoleDashboard: signupStatus.consoleURL, apiEndpoint: signupStatus.apiEndpoint, oauthTokenEndpoint: oauthInfo.token_endpoint, proxyUrl: signupStatus.proxyURL });
} else {
// cluster is not ready and the reason is
if (signupStatus.status.verificationRequired) {
Expand Down Expand Up @@ -173,7 +173,7 @@ async function clusterEditorMessageListener (event: any ): Promise<any> {
case 'sandboxLoginUsingDataInClipboard':
const telemetryEventLoginToSandbox = new ExtCommandTelemetryEvent('openshift.explorer.addCluster.sandboxLoginUsingDataInClipboard');
try {
const result = await Cluster.loginUsingClipboardToken(event.payload.apiEndpointUrl, event.payload.oauthRequestTokenUrl);
const result = await Cluster.loginUsingClipboardToken(event.payload.proxyUrl, (sessionCheck as any).idToken);
if (result) vscode.window.showInformationMessage(`${result}`);
telemetryEventLoginToSandbox.send();
} catch (err) {
Expand Down

0 comments on commit 88c5cf7

Please sign in to comment.