Skip to content

Commit 88c5cf7

Browse files
committed
Use proxyURL to log into sandbox using Red Hat auth token
Fix #2519. Signed-off-by: Denis Golovin [email protected]
1 parent 97f23a5 commit 88c5cf7

File tree

4 files changed

+19
-15
lines changed

4 files changed

+19
-15
lines changed

src/openshift/cluster.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -451,15 +451,15 @@ export class Cluster extends OpenShiftItem {
451451
@vsCommand('openshift.explorer.login.clipboard')
452452
static async loginUsingClipboardToken(apiEndpointUrl: string, oauthRequestTokenUrl: string): Promise<string | null> {
453453
const clipboard = await Cluster.readFromClipboard();
454-
if(!clipboard) {
455-
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.',
456-
'Get token');
457-
if (choice === 'Get token') {
458-
await commands.executeCommand('vscode.open', Uri.parse(oauthRequestTokenUrl));
459-
}
460-
return;
461-
}
462-
return Cluster.tokenLogin(apiEndpointUrl, true, clipboard);
454+
// if(!clipboard) {
455+
// 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.',
456+
// 'Get token');
457+
// if (choice === 'Get token') {
458+
// await commands.executeCommand('vscode.open', Uri.parse(oauthRequestTokenUrl));
459+
// }
460+
// return;
461+
// }
462+
return Cluster.tokenLogin(apiEndpointUrl, true, oauthRequestTokenUrl);
463463
}
464464

465465
static async loginUsingClipboardInfo(dashboardUrl: string): Promise<string | null> {

src/openshift/sandbox.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export interface SBSignupResponse {
2929
givenName: string;
3030
status: SBStatus;
3131
username: string;
32+
proxyURL: string;
3233
}
3334

3435
export interface SBResponseData {

src/webview/cluster/app/sandboxView.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ export default function addSandboxView(props): JSX.Element {
5959
consoleDashboard: '',
6060
apiEndpoint: '',
6161
oauthTokenEndpoint: '',
62-
errorCode: undefined
62+
errorCode: undefined,
63+
proxyUrl: ''
6364
});
6465

6566
const messageListener = (event) => {
@@ -151,7 +152,8 @@ export default function addSandboxView(props): JSX.Element {
151152
statusInfo: currentState.statusInfo,
152153
apiEndpoint: '',
153154
oauthTokenEndpoint: '',
154-
errorCode: undefined
155+
errorCode: undefined,
156+
proxyUrl: ''
155157
});
156158
postMessage('sandboxDetectStatus');
157159
}
@@ -302,7 +304,8 @@ export default function addSandboxView(props): JSX.Element {
302304
consoleDashboard: '',
303305
apiEndpoint: '',
304306
oauthTokenEndpoint: '',
305-
errorCode: undefined
307+
errorCode: undefined,
308+
proxyUrl: ''
306309
});
307310
}
308311

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

381384
const handleLoginButton = () => {
382-
postMessage('sandboxLoginUsingDataInClipboard', {apiEndpointUrl: currentState.apiEndpoint, oauthRequestTokenUrl: `${currentState.oauthTokenEndpoint}/request`});
385+
postMessage('sandboxLoginUsingDataInClipboard', {apiEndpointUrl: currentState.apiEndpoint, oauthRequestTokenUrl: `${currentState.oauthTokenEndpoint}/request`, proxyUrl: currentState.proxyUrl});
383386
};
384387

385388
return (

src/webview/cluster/clusterViewLoader.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ async function clusterEditorMessageListener (event: any ): Promise<any> {
109109
} else {
110110
if (signupStatus.status.ready) {
111111
const oauthInfo = await sandboxAPI.getOauthServerInfo(signupStatus.apiEndpoint);
112-
panel.webview.postMessage({action: 'sandboxPageProvisioned', statusInfo: signupStatus.username, consoleDashboard: signupStatus.consoleURL, apiEndpoint: signupStatus.apiEndpoint, oauthTokenEndpoint: oauthInfo.token_endpoint });
112+
panel.webview.postMessage({action: 'sandboxPageProvisioned', statusInfo: signupStatus.username, consoleDashboard: signupStatus.consoleURL, apiEndpoint: signupStatus.apiEndpoint, oauthTokenEndpoint: oauthInfo.token_endpoint, proxyUrl: signupStatus.proxyURL });
113113
} else {
114114
// cluster is not ready and the reason is
115115
if (signupStatus.status.verificationRequired) {
@@ -173,7 +173,7 @@ async function clusterEditorMessageListener (event: any ): Promise<any> {
173173
case 'sandboxLoginUsingDataInClipboard':
174174
const telemetryEventLoginToSandbox = new ExtCommandTelemetryEvent('openshift.explorer.addCluster.sandboxLoginUsingDataInClipboard');
175175
try {
176-
const result = await Cluster.loginUsingClipboardToken(event.payload.apiEndpointUrl, event.payload.oauthRequestTokenUrl);
176+
const result = await Cluster.loginUsingClipboardToken(event.payload.proxyUrl, (sessionCheck as any).idToken);
177177
if (result) vscode.window.showInformationMessage(`${result}`);
178178
telemetryEventLoginToSandbox.send();
179179
} catch (err) {

0 commit comments

Comments
 (0)