-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #85 from marcioaffonso/VIDECO-8004
[VIDECO-8004] - Update Insights-API samples with applicationIds
- Loading branch information
Showing
17 changed files
with
320 additions
and
231 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,3 +20,4 @@ | |
.env.production.local | ||
|
||
npm-debug.log* | ||
private.key |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
const jwt = require('jsonwebtoken'); | ||
const { v1 } = require('uuid'); | ||
|
||
const EXPIRATION_SECS = (60 * 60); // 1 hour | ||
|
||
const getCurrentTime = () => Math.floor(new Date() / 1000); | ||
|
||
/** | ||
* Generates a new token for TokBox users | ||
* @param apiKey - TokBox API Key | ||
* @param apiSecret - TokBox API Secret | ||
*/ | ||
const createTokenTokBox = (apiKey, apiSecret) => { | ||
const currentTime = getCurrentTime(); | ||
return jwt.sign({ | ||
iss: apiKey, | ||
ist: 'project', | ||
iat: currentTime, | ||
exp: currentTime + EXPIRATION_SECS | ||
}, apiSecret); | ||
}; | ||
|
||
/** | ||
* Generates a new token for Nexmo users | ||
* @param applicationId - Nexmo Application ID | ||
* @param privateKey - Buffer containing the private key | ||
*/ | ||
const createTokenNexmo = (applicationId, privateKey) => { | ||
if (!(privateKey instanceof Buffer)) { | ||
throw new Error("You must set up your private key file."); | ||
} | ||
const currentTime = getCurrentTime(); | ||
return jwt.sign({ | ||
iat: currentTime, | ||
jti: v1(), | ||
exp: currentTime + EXPIRATION_SECS, | ||
application_id: applicationId | ||
}, privateKey, { algorithm: "RS256" }); | ||
}; | ||
|
||
module.exports = { | ||
createTokenTokBox, | ||
createTokenNexmo, | ||
}; |
Oops, something went wrong.