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:
- Securing API tokens on Windows
- Securing API tokens on GitHub
- Securing API on Heroku
Securing API tokens on Windows:
To secure API token you need to define them in the environment variables.
- Search the
Environment Variablesyou will find Edit the Environment variables, open it. There, you will find these settings:
- Then go to Environment Variables. Click on the New button then add the API token with some variable name and take note of it:
- 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:
- You need to have the code pushed to GitHub. Open the Your Repo Settings tab as shown below.
Then open Secrets on the left side as shown in the above picture.
Then add new Secret with the key name and API token.
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.
- Open CMD and login to Heroku with Heroku login
- Go to your Project Folder
- Then use this command:
heroku config:set <Key>=<Value> <Key>=<Value>
Now you can use the key name anywhere in the project!
- First Create an app in the Heroku
- Go to the App settings tab
- Go to Config Vars and add your API tokens
That’s it for the post. I hope this post is helpful to you!