@@ -4,18 +4,29 @@ var config = require("../../../config");
44var { makeHttpCall } = require ( "../../../makeHttpCall" ) ;
55
66function getSignedJWTToken ( botId ) {
7- var appId , apiKey ;
7+ var appId , apiKey , jwtAlgorithm , jwtExpiry ;
8+ var defAlg = "HS256" ;
9+
810 if ( config . credentials [ botId ] ) {
911 appId = config . credentials [ botId ] . appId ;
1012 apiKey = config . credentials [ botId ] . apikey ;
1113 } else {
1214 appId = config . credentials . appId ;
1315 apiKey = config . credentials . apikey ;
1416 }
17+
18+ if ( config . jwt [ botId ] ) {
19+ jwtAlgorithm = config . jwt [ botId ] . jwtAlgorithm ;
20+ jwtExpiry = config . jwt [ botId ] . jwtExpiry ;
21+ } else {
22+ jwtAlgorithm = config . jwt . jwtAlgorithm ;
23+ jwtExpiry = config . jwt . jwtExpiry ;
24+ }
25+
1526 return jwt . encode ( {
1627 appId : appId ,
17- exp : Date . now ( ) / 1000 + ( config . jwt_expiry || 60 ) //set the default expiry as 60 seconds
18- } , apiKey ) ;
28+ exp : Date . now ( ) / 1000 + ( jwtExpiry || 60 ) //set the default expiry as 60 seconds
29+ } , apiKey , ( jwtAlgorithm || defAlg ) ) ;
1930}
2031
2132function makeRequest ( url , method , body , opts ) {
@@ -24,6 +35,7 @@ function makeRequest(url, method, body, opts) {
2435 opts = opts || { } ;
2536 headers = opts . headers || { } ;
2637 headers [ 'content-type' ] = 'application/json' ;
38+
2739 headers . auth = getSignedJWTToken ( botId ) ;
2840
2941 return new Promise ( function ( resolve , reject ) {
0 commit comments