You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"Using GitHub's API with Two-Factor Authentication (2FA) Enabled"
17
+
]
18
+
},
19
+
{
20
+
"cell_type": "markdown",
21
+
"metadata": {},
22
+
"source": [
23
+
"When you enable 2FA in GitHub, this setting carries over to your usage of the API. github3.py provides a simple interface to manage 2FA.\n",
24
+
"\n",
25
+
"First, you need to create a callback handler that will prompt the user for their token (which they will receive either by SMS or by checking a phone application)."
26
+
]
27
+
},
28
+
{
29
+
"cell_type": "code",
30
+
"collapsed": false,
31
+
"input": [
32
+
"def callback_handler():\n",
33
+
" prompt_str = 'Please enter your 2FA token now: '\n",
34
+
" try:\n",
35
+
" token = raw_input(prompt_str)\n",
36
+
" except NameError:\n",
37
+
" token = input(prompt_str)\n",
38
+
" return token"
39
+
],
40
+
"language": "python",
41
+
"metadata": {},
42
+
"outputs": [],
43
+
"prompt_number": 1
44
+
},
45
+
{
46
+
"cell_type": "markdown",
47
+
"metadata": {},
48
+
"source": [
49
+
"This handler will work on Python 2 and Python 3. (In Python 2, to prompt the user, you want to use `raw_input` but that was replaced in Python 3 with `input`.)\n",
50
+
"\n",
51
+
"This will simply ask the user to type in their token and then return it to github3.py. Naturally if you're developing a GUI, you want to write a different handler, but that is out of the scope of this example.\n",
52
+
"\n",
53
+
"To use the handler above you can pass it to the `github3.login` function."
"The beauty of using the callback means that it only is used when it is necessary. If you have 2FA turned off, you'll never be prompted.\n",
83
+
"\n",
84
+
"If you have 2FA enabled, then every call you make to the API will require you to provide a passcode. The tokens cannot be reliably cached by github3.py. To avoid this, the API documentation and github3.py suggest you create an API Token. You should decide which [scopes](https://developer.github.com/v3/oauth/#scopes) you want the token to have before creating."
"The call to `authorize` will create an `Authorization` object which has a token. With that you can pass the token to `login` and not have to worry about having to supply tokens generated by an mobile application or sent to your phone."
0 commit comments