Setapp provides 240+ carefully curated apps in one subscription! Get started with a free trial >
Originally published at maheshthedev.hashnode.dev.

Thumbnail art credits: techfunnel.com

If you are into the tech world for a while, I’m sure you heard about the word API. It stands for Application Program Interface. For example, Google has API which gives user details access to third party software.

Basically, API acts as a bridge to pass information to authenticated third-party software. To authenticate these third parties, an API token is required.

Many contributors use this API tokens to create some unique products like creating Telegram Bot, Slack Bot. Although the product gets built successfully, contributors can get organized by open-sourcing their code. But it’s very important that they secure the API token before they publish it to GitHub!

Different ways of Securing API:

  1. Securing API tokens on Windows
  2. Securing API tokens on GitHub
  3. Securing API on Heroku

Securing API tokens on Windows:

To secure API token you need to define them in the environment variables.

  1. Search the Environment Variables you will find Edit the Environment variables, open it. There, you will find these settings:

  1. Then go to Environment Variables. Click on the New button then add the API token with some variable name and take note of it:

  1. After adding this Variable then restart it.

Now you can use this API token across any code in your local system!

Securing API tokens on GitHub:

  1. You need to have the code pushed to GitHub. Open the Your Repo Settings tab as shown below.

  1. Then open Secrets on the left side as shown in the above picture.

  2. Then add new Secret with the key name and API token.

  3. Now this key works across the repository.

Secret Keys won’t be disclosed to any other users or third parties by GitHub.

Securing API tokens on Heroku:

In Heroku, you can do this in two ways either through Heroku CLI or Dashboard.

Heroku CLI

  1. Open CMD and login to Heroku with Heroku login
  2. Go to your Project Folder
  3. Then use this command: heroku config:set <Key>=<Value> <Key>=<Value>

Now you can use the key name anywhere in the project!

Heroku Dashboard:

  1. First Create an app in the Heroku
  2. Go to the App settings tab
  3. Go to Config Vars and add your API tokens

That’s it for the post. I hope this post is helpful to you!


Join discussions at our discord server >
Did you learn something new? Add a comment below and spread the word!



Contribute to the Genics Blog!

Genics Blog is a purely open source publication. Authors at Genics post highly resourceful content on varied topics relevant to the developer community. Join us and start publishing today!

Contribute

Comments

Related content