-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
36 lines (28 loc) · 1.2 KB
/
index.js
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
28
29
30
31
32
33
34
35
36
const BoostPlugin = require("../boost/api/plugins/BoostPlugin");
const crypto = require("crypto");
const {SecretManagerServiceClient} = require("@google-cloud/secret-manager");
const client = new SecretManagerServiceClient();
class GCSanctumAuthenticator extends BoostPlugin{
async onSanctumEncryptSecret(data, project_key) {
const config = require("../../../server.config");
const gc_project_id = (config.sanctum.gc_project_id !== undefined) ? config.sanctum.gc_project_id : null;
if(gc_project_id !== null){
let name = "projects/" + gc_project_id + "/secrets/sanctum-public/versions/latest";
const [version] = await client.accessSecretVersion({
name: name
});
const key = version.payload.data.toString();
try{
return crypto.publicEncrypt({
key: key,
padding: crypto.constants.RSA_PKCS1_OAEP_PADDING,
oaepHash: "sha256"
}, Buffer.from(JSON.stringify(data))).toString("base64");
}catch (e){
return null;
}
}
return null;
}
}
module.exports = GCSanctumAuthenticator;