11import * as vscode from 'vscode' ;
22import { Uri } from 'vscode' ;
3- import { extensionId } from '../extension' ;
3+ import { extensionId , ServerSpec } from '../extension' ;
44
55export async function getPortalUriWithCredentials ( name : string , scope ?: vscode . ConfigurationScope ) : Promise < Uri | undefined > {
66
@@ -10,22 +10,24 @@ export async function getPortalUriWithCredentials(name: string, scope?: vscode.C
1010 if ( typeof spec !== 'undefined' ) {
1111 const webServer = spec . webServer ;
1212 let queryString = '' ;
13+
14+ // We can only pass credentials in cleartext as a queryparam, so only do this if user was willing to store password in cleartext in settings.
15+ const settingsSpec : ServerSpec | undefined = vscode . workspace . getConfiguration ( 'intersystems.servers' , scope ) . get ( name ) ;
16+ spec . password = settingsSpec ?. password ;
1317
14- // At this point we don't know if the target is IRIS or Cache, so add credentials in both formats.
15- // Deliberately put password before username, otherwise it is visible in VS Code's confirmation dialog triggered target domain
16- // hasn't been set as trusted. Likewise, deliberately put IRIS* after Cache*
17- if ( spec ?. password ) {
18+ if ( spec ?. password && spec ?. username ) {
19+ // At this point we don't know if the target is IRIS or Cache, so add credentials in both formats.
20+ // Deliberately put password before username, otherwise it is visible in VS Code's confirmation dialog triggered target domain
21+ // hasn't been set as trusted. Likewise, deliberately put IRIS* after Cache*
1822 const passwordEncoded = encodeURIComponent ( spec . password ) ;
1923 queryString += `&CachePassword=${ passwordEncoded } &IRISPassword=${ passwordEncoded } ` ;
20- }
21- if ( spec ?. username ) {
2224 const usernameEncoded = encodeURIComponent ( spec . username ) ;
2325 queryString += `&CacheUsername=${ usernameEncoded } &IRISUsername=${ usernameEncoded } ` ;
26+
27+ // Add a cache-buster and push any credentials offscreen
28+ queryString = '_=' + new Date ( ) . getTime ( ) . toString ( ) . padEnd ( 480 , ' ' ) + queryString ;
2429 }
2530
26- // Add a dummy cache-buster and push the actual credentials offscreen
27- queryString = '_=' + new Date ( ) . getTime ( ) . toString ( ) . padEnd ( 480 , ' ' ) + queryString ;
28-
2931 return vscode . Uri . parse ( `${ webServer . scheme } ://${ webServer . host } :${ webServer . port } ${ webServer . pathPrefix } /csp/sys/UtilHome.csp?${ queryString } ` , true ) ;
3032 }
3133 } )
0 commit comments