-
-
Save cardoso/a18028d8c74891aed66fe82363cef98b to your computer and use it in GitHub Desktop.
Back4App and Virgil server
This file contains hidden or 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
const axios = require("axios"); | |
const { JwtGenerator } = require("virgil-sdk"); | |
const { VirgilCrypto, VirgilAccessTokenSigner } = require("virgil-crypto"); | |
const crypto = new VirgilCrypto(); | |
const APP_ID = "YOUR_VIRGIL_APP_ID"; | |
const APP_KEY = "YOUR_VIRGIL_APP_KEY"; | |
const APP_KEY_ID = "YOUR_VIRGIL_APP_ID"; | |
const PARSE_APP_ID = "YOUR_PARSE_APP_ID"; | |
const PARSE_REST_API_KEY = "YOUR_PARSE_REST_API_KEY"; | |
const generator = new JwtGenerator({ | |
appId: APP_ID, | |
apiKeyId: APP_KEY_ID, | |
apiKey: crypto.importPrivateKey(APP_KEY), | |
accessTokenSigner: new VirgilAccessTokenSigner(crypto) | |
}); | |
Parse.Cloud.define("virgil-jwt", function(request, response) { | |
const { sessionToken } = request.params; | |
return axios | |
.get("https://parseapi.back4app.com/users/me", { | |
headers: { | |
"X-Parse-Application-Id": PARSE_APP_ID, | |
"X-Parse-REST-API-Key": PARSE_REST_API_KEY, | |
"X-Parse-Session-Token": sessionToken | |
} | |
}) | |
.then(resp => { | |
const identity = resp.data.objectId; | |
const virgilJwtToken = generator.generateToken(identity); | |
response.success({ token: virgilJwtToken.toString() }); | |
}) | |
.catch(error => { | |
response.error(error.message); | |
}); | |
}); |
This file contains hidden or 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
{ | |
"dependencies": { | |
"axios": "^0.18.0", | |
"virgil-crypto": "^3.2.1", | |
"virgil-sdk": "^5.2.2" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment