How to store OAuth token for Github in a Python script?
Question: I am working on a Python script that access Github using basic authentication.
I want to use OAuth so that user doesn't have to enter credentials every time
he uses the script. Most importantly, user's password does not get saved in
the `.bash_history`.

This Github API has the code to get token using [Basic
authentication](http://developer.github.com/v3/oauth/#create-a-new-
authorization).

    
    
    `curl -u $USER_NAME --silent https://api.github.com/authorizations`
    

User is asked to enter password and gets token in the response.

  1. Now where do I save this token securely so that next time when the script is run user doesn't have to enter anything?
  2. The aim is to avoid storing the password or asking the user to enter every time he uses the script. Is there some other way to achieve these?


Answer: You should probably save the token in a config file in the user's home
directory. Preferably, you can restrict permissions on the file to make sure
that only that user may access the config file.

