Skip to main content
Version: 0.1.0

CookieAuthenticationCredential

The CookieAuthenticationCredential class provides functions to check the authentication status of a given endpoint.

Constructor​

new CookieAuthenticationCredential(configuration)​

Creates a new instance of CookieAuthenticationCredential.

Parameters​

  • configuration: object
    • url: string - The URL of the SAS Viya server that you are authenticating with.
    • guest: boolean - (Optional) Automatically log in as a guest, if no user session is found.
      • Default value: false

Example​

import { CookieAuthenticationCredential } from '@sassoftware/sas-auth-browser';

const sasAuthInstance = new CookieAuthenticationCredential({
url: 'https://my-viya-server.com',
guest: false,
});

Methods​

checkAuthenticated(): Promise<void>​

Checks to see if any user is authenticated.

Returns​

Promise<void> - Resolves if a user is authenticated.

Rejects​

If no user is authenticated.

Example​

try {
await sasAuthInstance.checkAuthenticated();
console.log('User is authenticated');
} catch (error) {
console.log('User is not authenticated');
}

loginPopup(): Promise<void>​

Launches a popup window that navigates to the authentication endpoint and allows the user to login.

Returns​

Promise<void> - Resolves when login is successful.

Rejects​

When login fails (for example: user closes the popup).

Example​

try {
await sasAuthInstance.loginPopup();
console.log('Login successful');
} catch (error) {
console.log('Login failed or popup was closed');
}

logout(): Promise<void>​

Makes an endpoint call to the SAS Viya server that ends the cookie based browser session.

Returns​

Promise<void> - Resolves when logout is successful.

Rejects​

When sign out fails.

Example​

try {
await sasAuthInstance.logout();
console.log('Logout successful');
} catch (error) {
console.log('Logout failed');
}

invalidateCache(): void​

If checkAuthenticated has already been called, a cached value may be returned the next time. This is done to reduce the number of potential service calls needed when making multiple API calls. Calling invalidateCache will force checkAuthenticated to re-validate the next time it is called.

Note: This is not needed for most use cases.

Returns​

void

Example​

sasAuthInstance.invalidateCache();
await sasAuthInstance.checkAuthenticated(); // Will perform a fresh check