mirror of
https://github.com/donl/plivo-node.git
synced 2026-06-30 06:12:08 -06:00
add jwt examples
This commit is contained in:
parent
48aeba2fef
commit
ac927714b3
2 changed files with 15 additions and 2 deletions
13
examples/jwt.js
Normal file
13
examples/jwt.js
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
var Plivo = require('../dist/rest/client.js');
|
||||
|
||||
// token generation using from epoch and length in seconds
|
||||
var acctkn = new Plivo.AccessToken('{authId}', '{authToken}', 'endpointUsername', {validFrom: (new Date()).getTime()/1000, lifetime: 300}, 'username-12345');
|
||||
console.log(acctkn.toJwt());
|
||||
|
||||
|
||||
// token with validity of 24 hours starting now
|
||||
acctkn = new Plivo.AccessToken('{authId}', '{authToken}', 'endpointUsername', {}, 'uid');
|
||||
|
||||
// voice (incoming, outgoing) grants
|
||||
acctkn.addVoiceGrants(true, true);
|
||||
console.log(acctkn.toJwt());
|
||||
|
|
@ -25,10 +25,10 @@ export function AccessToken(authId, authToken, username, validityOptions = {}, u
|
|||
if (validityOptions.validTill != null) {
|
||||
this.lifetime = validityOptions.validTill - this.validFrom;
|
||||
} else {
|
||||
this.lifetime = 84600;
|
||||
this.lifetime = 86400;
|
||||
}
|
||||
} else {
|
||||
this.lifetime = validityOptions.lifetime || 84600;
|
||||
this.lifetime = validityOptions.lifetime || 86400;
|
||||
if (validityOptions.validTill != null) {
|
||||
this.validFrom = validityOptions.validTill - this.lifetime;
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue