@microsoft/windows-admin-center-sdk
Version:
Microsoft - Windows Admin Center Shell
57 lines (55 loc) • 1.54 kB
JavaScript
import { EnvironmentModule } from '../manifest/environment-modules';
/**
* Cookie class.
*/
export class Cookie {
/**
* Gets cookie by name.
*/
static get(cookieName) {
const name = cookieName + '=';
const ca = document.cookie.split(';');
for (let i = 0; i < ca.length; i++) {
let c = ca[i];
while (c.charAt(0) === ' ') {
c = c.substring(1);
}
if (c.indexOf(name) === 0) {
return c.substring(name.length, c.length);
}
}
return null;
}
/**
* "clears" cookie by name. Setting its expiration date to "Thu, 01 Jan 1970 00:00:00 GMT"
*/
static clear(cookieName) {
const dawnOfTime = new Date(0).toUTCString();
document.cookie = `${cookieName}=;expires=${dawnOfTime}`;
}
/**
* Gets the cross site request forgery token.
*/
static getCrossSiteRequestForgeryToken() {
if (EnvironmentModule.isGatewayV200) {
const xsrf = Cookie.get('WAC-XSRF');
if (xsrf) {
return xsrf;
}
}
return Cookie.get('XSRF-TOKEN');
}
/**
* Gets the gateway identity token.
*/
static getGatewayIdentityToken() {
return Cookie.get('GATEWAY-IDENTITY-TOKEN');
}
/**
* Clears the gateway identity token.
*/
static clearGatewayIdentityToken() {
Cookie.clear('GATEWAY-IDENTITY-TOKEN');
}
}
//# sourceMappingURL=cookie.js.map