7

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

KENdi
  • 7,576
  • 2
  • 16
  • 31
Philip Nord
  • 141
  • 1
  • 11

1 Answers1

7

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.

Philip Nord
  • 141
  • 1
  • 11
  • don't put your cert passphrase in the options. instead use environment variables for sensitive stuff like the passphrase. https://firebase.google.com/docs/functions/config-env – Andrew Jul 30 '19 at 12:05
  • how did you generate certificates in a first place? It said that you need to "generate it on your server" in every documentation. But firebase has no ssh to login to, did you do it locally and then uploaded? Did it work? Thanks – Anton Aug 23 '19 at 21:52
  • Trying the same. Have added my .p12 to the same folder as index.js but I get the following error: {"code":"UNABLE_TO_VERIFY_LEAF_SIGNATURE"} – Sunkas Mar 13 '20 at 07:56