问题
I'm trying to figure out if it is possible to upload a TLS client certificate to be used for my cloud functions in firebase. The TLS client certificate is required by a third-party payment solution called Swish.
This is my first firebase project and it seems silly that a small issue like this will render the platform unusable for me..
回答1:
After some headache and trying I found a quite easy way to solve swish-payments through cloud functions:
Using request-js instead of the built in libraries, I only need to build the options object to use in the request.post() method as following:
const swishOptions = {
url: 'LINK TO SWISH SERVER',
json: true,
pfx: fs.readFileSync('cert.p12'),
passphrase: 'swish',
body: swishRequestBody
}
The cert.p12-file should be placed in the same folder as index.js and will be uploaded together with the functions.
rq.post(swishOptions, (err, res) => {
if (err){
console.log('payment creation error: ' + JSON.stringify(err))
reject(err)
}
if (res){
console.log('Payment-token: ' + res.headers.paymentrequesttoken)
}
});
The body-object should contain all fields specified in the Swish API, use console.log() to read the error-messages from the Swish-server.
来源:https://stackoverflow.com/questions/45856469/upload-tls-client-certificate-to-firebase-cloud-functions