N
N
nikto_2112022-01-19 16:41:24
Python
nikto_211, 2022-01-19 16:41:24

How to properly hide the token?

There is a
Config.py file, it contains:
access_token = "here is the token itself"
And there is a main.py file that reads the config via config.access_token
How can I remove the token from the repository, but put it in the secrets section, I want to open the code, but if I remove the token completely, then I won’t be able to deploy to Heroku

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexander Nesterov, 2022-01-19
@AlexNest

Save it to heroku environment variable and call it via:
os.environ['var_name']

I
igorzakhar, 2022-01-19
@igorzakhar

Menu item "Settings" in Heroku admin panel:
61e838a57aeaa032563790.png
Click "Reveal Config Vars" button, add environment variables:
61e8392da7e75577329883.png
Or via Heroku CLI ( https://devcenter.heroku.com/articles/config-vars ):

heroku config:set GITHUB_USERNAME=joesmith
Adding config vars and restarting myapp... done, v12
GITHUB_USERNAME: joesmith

In code, for example:
access_token = os.getenv("ACCESS_TOKEN")
...

R
Rag'n' Code Man, 2022-01-19
@iDmitriyWinX

We store all such information in server environment variables, this is also possible on Heroku.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question