mirror of
https://github.com/donl/plivo-node.git
synced 2026-06-30 06:12:08 -06:00
Added corrections in Token Creation
This commit is contained in:
parent
ee6b011677
commit
c946ab3185
3 changed files with 43 additions and 31 deletions
|
|
@ -1,5 +1,9 @@
|
|||
# Change Log
|
||||
|
||||
## [v4.34.0](https://github.com/plivo/plivo-go/tree/v4.34.0) (2022-08-07)
|
||||
**Feature - Token Creation**
|
||||
- `JWT Token Creation API` added API to create a new JWT token.
|
||||
|
||||
## [v4.33.0](https://github.com/plivo/plivo-go/tree/v4.33.0) (2022-07-11)
|
||||
**Feature - STIR Attestation**
|
||||
- Add stir attestation param as part of Get CDR and Get live call APIs Response
|
||||
|
|
|
|||
|
|
@ -25,13 +25,13 @@ export class CreateTokenResponse {
|
|||
/**
|
||||
* Represents a Token Interface
|
||||
* @constructor
|
||||
* @param {function} client - make api call
|
||||
* @param {function} client - make api Token
|
||||
* @param {object} [data] - data of Token
|
||||
*/
|
||||
export class TokenInterface extends PlivoResourceInterface {
|
||||
|
||||
constructor(client, data = {}) {
|
||||
super(action, TokenInterface, idField, client);
|
||||
super(action, TokenInterface, client);
|
||||
extend(this, data);
|
||||
|
||||
this[clientKey] = client;
|
||||
|
|
@ -40,49 +40,57 @@ export class CreateTokenResponse {
|
|||
* Create a token
|
||||
* @method
|
||||
* @param {string} iss - Auth id of the user
|
||||
* @param {string} sub - Subject
|
||||
* @param {number} nbf - Start time of the token
|
||||
* @param {number} exp - Expiration time of the token
|
||||
* @param {boolean} incoming_allowed - Incoming allowed
|
||||
* @param {boolean} outgoing_allowed - Outgoing allowed
|
||||
* @param {string} app - App id
|
||||
* @promise {object} returns PlivoGenericResponse Object
|
||||
* @param {object} optionalParams - Optional Params to send message
|
||||
* @param {string} [optionalParams.sub] - subject of the token
|
||||
* @param {string} [optionalParams.exp] - expiration time of the token
|
||||
* @param {string} [optionalParams.nbf] - not before time of the token
|
||||
* @param {boolean} [optionalParams.incoming_allow] - incoming allow of the token
|
||||
* @param {boolean} [optionalParams.outgoing_allow] - outgoing allow of the token
|
||||
* @param {string} [optionalParams.app] - app id of the token
|
||||
* @param {json} [optionalParams.per] - permissions of the token
|
||||
* @promise {object} return {@link PlivoGenericMessage} object if success
|
||||
* @fail {Error} returns Error
|
||||
*/
|
||||
create(iss,sub,nbf,exp,incoming_allowed,outgoing_allowed,app, params = {}) {
|
||||
let errors = validate([{
|
||||
create(iss, optionalParams = {}) {
|
||||
|
||||
let errors = validate([{
|
||||
field: 'iss',
|
||||
value: iss,
|
||||
validators: ['isRequired']
|
||||
}
|
||||
},
|
||||
]);
|
||||
if(incoming_allowed == true && sub == null){
|
||||
errors.push({
|
||||
field: 'sub',
|
||||
value: sub,
|
||||
validators: ['isRequired']
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
if (errors) {
|
||||
return errors;
|
||||
return errors;
|
||||
}
|
||||
|
||||
let params = optionalParams || {};
|
||||
params.per = {};
|
||||
params.per.voice = {};
|
||||
if(optionalParams.sub) {
|
||||
params.sub = optionalParams.sub;
|
||||
}
|
||||
if(optionalParams.exp) {
|
||||
params.exp = optionalParams.exp;
|
||||
}
|
||||
if(optionalParams.nbf) {
|
||||
params.nbf = optionalParams.nbf;
|
||||
}
|
||||
if(optionalParams.incoming_allow) {
|
||||
params.per.voice.incoming_allow = optionalParams.incoming_allow;
|
||||
}
|
||||
if(optionalParams.outgoing_allow) {
|
||||
params.per.voice.outgoing_allow = optionalParams.outgoing_allow;
|
||||
}
|
||||
if(optionalParams.app) {
|
||||
params.app = optionalParams.app;
|
||||
}
|
||||
params.iss = iss;
|
||||
params.sub = sub;
|
||||
params.nbf = nbf;
|
||||
params.exp = exp;
|
||||
params.incoming_allowed = incoming_allowed;
|
||||
params.outgoing_allowed = outgoing_allowed;
|
||||
params.app = app;
|
||||
params.isVoiceRequest = 'true';
|
||||
|
||||
let client = this[clientKey];
|
||||
return new Promise((resolve, reject) => {
|
||||
client('POST', action, params)
|
||||
.then(response => {
|
||||
resolve(new CreateTokenResponse(response.body, idField));
|
||||
resolve(new CreateTokenResponse(response.body));
|
||||
})
|
||||
.catch(error => {
|
||||
reject(error);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "plivo",
|
||||
"version": "4.33.0",
|
||||
"version": "4.34.0",
|
||||
"description": "A Node.js SDK to make voice calls and send SMS using Plivo and to generate Plivo XML",
|
||||
"homepage": "https://github.com/plivo/plivo-node",
|
||||
"files": [
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue