-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use REST to get a CSPCHD token with which to access Portal
- Loading branch information
1 parent
8fc9697
commit 5ca74e3
Showing
4 changed files
with
50 additions
and
46 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import * as vscode from 'vscode'; | ||
import { Uri } from 'vscode'; | ||
import { extensionId, ServerSpec } from '../extension'; | ||
import { makeRESTRequest } from '../makeRESTRequest'; | ||
|
||
const allTokens = new Map<string, string>(); | ||
|
||
export async function getPortalUriWithToken(name: string, scope?: vscode.ConfigurationScope): Promise<Uri | undefined> { | ||
|
||
const PORTAL_HOME = '/csp/sys/UtilHome.csp'; | ||
|
||
// Use our own API so that the Recent folder updates with our activity | ||
const myApi = vscode.extensions.getExtension(extensionId)?.exports; | ||
|
||
const spec: ServerSpec | undefined = await myApi.getServerSpec(name, scope); | ||
if (typeof spec !== 'undefined') { | ||
|
||
// Retrieve previously cached token | ||
let token = allTokens.get(name) || ''; | ||
|
||
// Revalidate and extend existing token, or obtain a new one | ||
const response = await makeRESTRequest("POST", spec, { apiVersion: 1, namespace: '%SYS', path:'/action/query' }, { query: 'select %Atelier_v1_Utils.General_GetCSPToken(?, ?) token', parameters: [PORTAL_HOME, token]}); | ||
|
||
if (!response) { | ||
// User will have to enter credentials | ||
token = ''; | ||
allTokens.delete(name); | ||
} | ||
else { | ||
token = response.data?.result?.content[0]?.token || ''; | ||
allTokens.set(name, token); | ||
} | ||
|
||
const webServer = spec.webServer; | ||
let queryString = token ? `CSPCHD=${encodeURIComponent(token)}` : ''; | ||
|
||
return vscode.Uri.parse(`${webServer.scheme}://${webServer.host}:${webServer.port}${webServer.pathPrefix}${PORTAL_HOME}?${queryString}`, true); | ||
} | ||
} |
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
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