-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauth.py
44 lines (32 loc) · 1.45 KB
/
auth.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env python3
'''
Here's how you go about authenticating yourself! The important thing to
note here is that this script will be used in the other examples so
set up a test user with API credentials and set them up in auth.ini.
'''
from imgurpython import ImgurClient
from helpers import get_input, get_config
def authenticate():
# Get client ID and secret from auth.ini
config = get_config()
config.read('auth.ini')
client_id = config.get('credentials', 'client_id')
client_secret = config.get('credentials', 'client_secret')
access_token = config.get('credentials', 'access_token')
refresh_token = config.get('credentials', 'refresh_token')
client = ImgurClient(client_id, client_secret, access_token, refresh_token)
# Authorization flow, pin example (see docs for other auth types)
#authorization_url = client.get_auth_url('pin')
#print("Go to the following URL: {0}".format(authorization_url))
# Read in the pin, handle Python 2 or 3 here.
#pin = get_input("Enter pin code: ")
# ... redirect user to `authorization_url`, obtain pin (or code or token) ...
#credentials = client.authorize(pin, 'pin')
client.set_user_auth(access_token, refresh_token)
print("Authentication successful!")
#print(" Access token: {0}".format(credentials['access_token']))
#print(" Refresh token: {0}".format(credentials['refresh_token']))
return client
# If you want to run this as a standalone script, so be it!
if __name__ == "__main__":
authenticate()