10000 Add a documented example · bryankaplan/github3.py@7121b26 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7121b26

Browse files
committed
Add a documented example
1 parent 4d95713 commit 7121b26

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

docs/examples/two_factor_auth.rst

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
Using Two Factor Authentication with github3.py
2+
===============================================
3+
4+
GitHub recently added support for Two Factor Authentication to ``github.com``
5+
and shortly thereafter added support for it on ``api.github.com``. In version
6+
0.8, github3.py also added support for it and you can use it right now.
7+
8+
To use Two Factor Authentication, you must define your own function that will
9+
return your one time authentication code. You then provide that function when
10+
logging in with github3.py.
11+
12+
For example:
13+
14+
.. code::
15+
16+
import github3
17+
18+
try:
19+
# Python 2
20+
prompt = raw_input
21+
except NameError:
22+
# Python 3
23+
prompt = input
24+
25+
def my_two_factor_function():
26+
code = ''
27+
while not code:
28+
code = prompt('Enter 2FA code: ')
29+
return code
30+
31+
g = github3.login('sigmavirus24', 'my_password',
32+
two_factor_callback=my_two_factor_function)
33+
34+
Then if the API tells github3.py it requires a Two Factor Authentication code,
35+
github3.py will call ``my_two_factor_function`` and prompt you for it.

0 commit comments

Comments
 (0)
0