I'm trying to create a front end html page which contains a form to collect information necessary to submit a JES job. The form contains dynamically generated select lists based on lookup tables stored in CAS. The oauth "client_credentials" flow works fine when executed in SAS Studio, but fails to get a valid session id when running the same job html within a web content object in Visual Analytics. It seems the session information returned from the request is different depending on where the job's html is run. In SAS Studio, a single session id is returned and works fine. In VA, a collection is returned and I'm trying to get a session id, but the id is not valid for any downstream data requests. The code used to get the session Id with a valid access token (Viya 3.5): async function getCASSession(accessToken) {
// Define request header object
var reqHeader = new Headers();
reqHeader.append("Authorization", "Bearer " + accessToken);
reqHeader.append("Content-Type", "application/vnd.sas.cas.session+json");
reqHeader.append("Accept", "application/json");
// Fetch the session id with a valid access token
try {
const response = await fetch('https://MyReportServer/casManagement/servers/cas-shared-default/sessions', {
method: 'GET',
headers: reqHeader
});
// Test the fetch response
if (!response.ok) {
const message = `Fetch error with status code: ${response.status}`;
throw new Error(message);
}
// Process and return the response
const sessionData = await response.json();
// The session id may be returned in a collection when running inside VA
if (sessionData.id === undefined) {
var sessionId = sessionData.items[0].id;
} else {
var sessionId = sessionData.id;
}
// Log out data and session id
// console.log(sessionData);
console.log(`The session identifier is: ${sessionId}`);
// Return the session id
return sessionId;
// Trap errors in the fetched data
} catch (err) {
console.log(`Error: Could not acquire the CAS session. ${err}`);
}
} // end getCASSession In SAS Studio a single session id is returned as is used for subsequent api calls to get data. In VA a collection is returned but the session is not valid when trying to use it. {
"error": "Unknown session.",
"code": "SessionUnknown",
"details": "59f4b7eb-c000-2e49-8b02-f4b3fcde3b51",
"disposition": null
} Any insight or help would be much appreciated.
... View more