Home Reference Source
public class | source

CWT

A consent web token represents the GDPR consents expressed by a user. It can be used for storage or to be shared with third-parties.

Example:

const token = new CWT({
  issuer: 'issuer',
  user_id: 'user@domain.com',
  user_id_type: 'email'
});

Constructor Summary

Public Constructor
public

constructor(tokenContent: Object)

Create a new Consent web token

Member Summary

Public Members
public

A list of consents already given by the user

public

A unique ID identifying the issuer of the token

public

The ID of the user that owns the token

public

If the user ID is hashed, this is the method used for generating the hash (md5, sha1, sha256)

public

The type of ID (email, uuid, adid, etc.)

public

The CWT specification version

Method Summary

Public Methods
public

getConsentStatus(purpose: string, vendorId: string): boolean

Get the consent status of the user for a specific purpose/vendor

public

setConsentStatus(status: string, purpose: string, vendorId: string)

Set the consent status for the user

public

Generate a base64-encoded version of the token It first encode the token as JSON then base64-encode it.

public

Generate a JSON-encoded version of the token

public

Export the token information as a plain JavaScript object

Public Constructors

public constructor(tokenContent: Object) source

Create a new Consent web token

Params:

NameTypeAttributeDescription
tokenContent Object

The content of the token

tokenContent.issuer string

A unique ID identifying the issuer of the token

tokenContent.user_id string
  • optional

The ID of the user that owns the token

tokenContent.user_id_type string
  • optional

The type of ID (email, uuid, adid, etc.)

tokenContent.user_id_hash_method string
  • optional

If the user ID is hashed, this is the method used for generating the hash (md5, sha1, sha256)

tokenContent.consents Object[]
  • optional

A list of consents already given by the user

Public Members

public consents: Object[] source

A list of consents already given by the user

public issuer: string source

A unique ID identifying the issuer of the token

public user_id: string source

The ID of the user that owns the token

public user_id_hash_method: string source

If the user ID is hashed, this is the method used for generating the hash (md5, sha1, sha256)

public user_id_type: string source

The type of ID (email, uuid, adid, etc.)

public version: number source

The CWT specification version

Public Methods

public getConsentStatus(purpose: string, vendorId: string): boolean source

Get the consent status of the user for a specific purpose/vendor

Returns true if consent has been given, false if consent has been denied and undefined if no consent information is available

Params:

NameTypeAttributeDescription
purpose string

Purpose

vendorId string

Unique ID of the vendor to check consent for

Return:

boolean

Example:

const token = new CWT('issuer');
token.setConsentStatus(CWT.Purposes.Cookies, 'didomi');
token.getConsentStatus(CWT.Purposes.Cookies, 'didomi');

public setConsentStatus(status: string, purpose: string, vendorId: string) source

Set the consent status for the user

Params:

NameTypeAttributeDescription
status string

The consent status (yes/no) of the user for the vendor

purpose string

The purpose for which the user has given consent

vendorId string

The unique vendor ID for which the user has given consent. Use * to indicate that the user has given consent for all vendors)

Example:

const token = new CWT('issuer');
token.setConsentStatus(
  true,
  CWT.Purposes.Cookies,
  'didomi'
);

public toBase64(): string source

Generate a base64-encoded version of the token It first encode the token as JSON then base64-encode it.

Return:

string

public toJSON(): string source

Generate a JSON-encoded version of the token

Return:

string

public toObject(): Object source

Export the token information as a plain JavaScript object

Return:

Object