-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathvirgilToken.js
More file actions
27 lines (20 loc) · 805 Bytes
/
virgilToken.js
File metadata and controls
27 lines (20 loc) · 805 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
const { JwtGenerator } = require('virgil-sdk');
const { initCrypto, VirgilCrypto, VirgilAccessTokenSigner } = require('virgil-crypto');
const config = require('./config');
async function getJwtGenerator() {
await initCrypto();
const virgilCrypto = new VirgilCrypto();
return new JwtGenerator({
appId: config.virgil.appId,
apiKeyId: config.virgil.appKeyId,
apiKey: virgilCrypto.importPrivateKey(config.virgil.appKey),
accessTokenSigner: new VirgilAccessTokenSigner(virgilCrypto)
});
}
const generatorPromise = getJwtGenerator();
const generateVirgilJwt = async (req, res) => {
const generator = await generatorPromise;
const virgilJwtToken = generator.generateToken(req.user.identity);
res.json({ virgilToken: virgilJwtToken.toString() });
}
module.exports = { generateVirgilJwt };