File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change
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.
You can’t perform that action at this time.
0 commit comments