Reputation: 165
Is there a secure way for public (shared with someone) Google Colaboratory notebooks to import security sensitive variables like access tokens?
I have a notebook with code like this one:
TOKEN='7o6kti1TW7ebwXXG6ZAdVkS08MzDBLG00oXTCNTYEbB5A'
items = json.loads(
requests.get('https://someservice.com/api/items?access_token={}'.format(TOKEN)).text
)
I want share the notebook with other users so they are able to run and edit code cells, but I want to move TOKEN variable definition to some hidden place. Is there a way to achieve that?
Upvotes: 2
Views: 2876
Reputation: 38619
One option is to assign the token at invocation time using getpass
.
Here's an example: https://colab.research.google.com/drive/1bjBVx6pokBm_A1em-XdURQAmemlUAgYz
from getpass import getpass
token = getpass('Enter token here')
print ('token is', token)
Upvotes: 6
Reputation: 1044
Here is the code inside @Bob Smith's linked colab
from getpass import getpass
token = getpass('Enter token here')
print ('token is', token)
Upvotes: 1