Upload TLS client certificate to Firebase cloud functions

孤街醉人 提交于 2021-02-07 03:29:33

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!