Getting started
The SAS Auth Browser package provides an API that allows for an application or web page to ensure that a user is authenticated before making SAS API calls or using SAS web components. Currently only cookie-based authentication is supported.
Prerequisites
In order to successfully make browser based REST calls to SAS Viya endpoints using cookies, you will need to enable CORS, Cross-site cookies and CSRF web security settings. For more information, see the SAS Viya setup guide.
Installation
NPM
npm install @sassoftware/sas-auth-browser
CDN
<script
async
src="https://cdn.developer.sas.com/packages/sas-auth-browser/latest/dist/index.min.js"
></script>
Usage
A simple example that uses sas-auth-browser is provided in the examples directory.
Additionally, before a rest API call is made to the SAS Viya server, you should first check to see if the cookie session is still valid.
const sasAuthInstance = sasAuthBrowser.createCookieAuthenticationCredential({
url,
});
async function callViyaApi() {
try {
await sasAuthInstance.checkAuthenticated();
} catch {
// Note: If the user closes the popup an uncaught exception will occur.
await sasAuthInstance.loginPopup();
}
// Start making rest calls!
}