Constructor
new CAT(opts)
Parameters:
Name | Type | Description |
---|---|---|
opts |
CatOptions | Options for the CAT object |
Example
const validator = new CAT({
keys: {
Symmetric256: Buffer.from(
'403697de87af64611c1d32a05dab0fe1fcb715a86ab435f1ec99192d79569388',
'hex'
)
},
});
try {
await validator.validate(base64encoded, 'mac', {
kid: 'Symmetric256',
issuer: 'coap://as.example.com'
});
} catch (e) {
// Not valid, handle error
}
Classes
Methods
(async) generateFromJson()
Generate a CAT token from a JSON object
Example
const base64encoded = await generator.generateFromJson(
{
iss: 'coap://as.example.com',
sub: 'jonas',
aud: 'coap://light.example.com',
exp: 1444064944,
nbf: 1443944944,
iat: 1443944944,
catr: {
type: 'header',
'header-name': 'cta-common-access-token',
expadd: 120,
deadline: 60
}
},
{
type: 'mac',
alg: 'HS256',
kid: 'Symmetric256',
generateCwtId: true // automatically generate a random CWT Id (cti) claim (default: false)
}
);
(async) generateFromJson(dict, optsopt)
Generate a CAT token from a JSON object
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
dict |
CommonAccessTokenDict | The claims to use for the token | |
opts |
CatGenerateOptions |
<optional> |
Options for the token generation |
Example
const base64encoded = await generator.generateFromJson(
{
iss: 'coap://as.example.com',
sub: 'jonas',
aud: 'coap://light.example.com',
exp: 1444064944,
nbf: 1443944944,
iat: 1443944944,
catr: {
type: 'header',
'header-name': 'cta-common-access-token',
expadd: 120,
deadline: 60
}
},
{
type: 'mac',
alg: 'HS256',
kid: 'Symmetric256',
generateCwtId: true // automatically generate a random CWT Id (cti) claim (default: false)
}
);
(async) renewToken()
Renew a CAT token
(async) renewToken(cat, opts) → {Promise.<string>}
Renew a CAT token
Parameters:
Name | Type | Description |
---|---|---|
cat |
CommonAccessToken | The token to renew |
opts |
CatRenewOptions | Options for the renewal |
Returns:
- Type
- Promise.<string>
(async) validate()
Validate a CAT token
Example
try {
await validator.validate(base64encoded, 'mac', {
kid: 'Symmetric256',
issuer: 'coap://as.example.com'
});
} catch (e) {
// Not valid, handle error
}
(async) validate(token, type, opts) → {Promise.<CatValidationResult>}
Validate a CAT token
Parameters:
Name | Type | Description |
---|---|---|
token |
string | The token to validate (base64 encoded) |
type |
CatValidationTypes | Type of validation to perform |
opts |
CatValidationOptions | Options for the validation |
Returns:
- Type
- Promise.<CatValidationResult>
Example
try {
await validator.validate(base64encoded, 'mac', {
kid: 'Symmetric256',
issuer: 'coap://as.example.com'
});
} catch (e) {
// Not valid, handle error
}