Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Upload TLS client certificate to Firebase cloud functions

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..

like image 395
Philip Nord Avatar asked Aug 24 '17 08:08

Philip Nord


1 Answers

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.

like image 111
Philip Nord Avatar answered Sep 30 '22 16:09

Philip Nord