Storing Authentication Tokens in Serverless App on Freshdesk

We are building a serverless app, where we need to store authentication token provided by an external gateway in FD for 24 hrs and use it for each SMS api call till 24 hrs.

Please help to get the confirmation if there is any mechanism by which we can store the token in an FD app.

Hi Rohan

Can you try to see our Data Storage feature: You can very well use $db.set with a ttl feature and get the token accordingly
Please take a look at the following sections

Additionaly you can make use of ttl option. Please let me know if this helped

Shravan Balasubramanian

1 Like

Hi Team,

I have one question here. We are supposed write a severless app which has a function-onTicket creation.
Inside OnTicket creation function, we need to call an API and in the response, we will get a token which we need to store. As per the datastorage links given above, we can see that client.db.set has to be done before function definition. Can you please suggest how to do the following:

  1. In serverless app, inside ticket creation function, we need to call an API and then in the function itself , we need to set the token there.

Hello Rohan,

As @shravan.balasubraman suggested above, you could set a ttl to your db key when it is created, to ensure that it expires every 24hrs. Every time your onTicketCreate handler executes, you can perform a db.get() to check if you already have the token stored. If db.get() fails, you know you have to fetch a new token, store it using db.set() and then continue onward with your API call.

I would think this should work for your use-case.

For additional security, I would recommend that you do not store the token as-is using db.set(). Apply some basic encryption, or at a minimum some encoding, to your token before you store the same.

1 Like