-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathrefresh_token.py
49 lines (34 loc) · 1.46 KB
/
refresh_token.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
45
46
47
48
49
"""Helper function to get refresh tokens
These are needed both in the general testing library and for
general development of library.
"""
from pathlib import Path
import pyimgur
def get_refresh_token():
"""Get and set refresh token for authentication with Imgur"""
im = pyimgur.Imgur(
client_id, client_secret # pylint: disable=used-before-assignment)
)
auth_url = im.authorization_url("pin")
print("Go to the following url to authenticate with your app")
print(auth_url)
pin = input("What is the pin? ")
access_token, refresh_token = im.exchange_pin(pin)
print("You have succesfully authenticated")
print(f"Refresh Token: {refresh_token}")
print(f"Access Token: {access_token}")
with open("authentication.py", "wb") as outfile:
outfile.write(f'client_id = "{client_id}"\n')
outfile.write(f'client_secret = "{client_secret}"\n')
outfile.write(f'refresh_token = "{refresh_token}"\n')
print()
print("Authentication.py file has been created with credentials.")
print("It is needed for test suite and for development.")
if __name__ == "__main__":
if not Path("authentication.py").exists():
print("ERROR: Cannot get refresh token without knowing client_id and secret")
print("Create a file called authentication.py and set client_id and")
print("client_secret in it.")
else:
from authentication import client_id, client_secret
get_refresh_token()