-
Notifications
You must be signed in to change notification settings - Fork 0
/
authorizer.py
65 lines (52 loc) · 1.63 KB
/
authorizer.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python3
import requests
import sys
import json
import os
from dotenv import load_dotenv, dotenv_values
load_dotenv()
POCKET_APP_NAME = os.environ.get("POCKET_APP_NAME")
POCKET_API_CONSUMER_KEY = os.environ.get("POCKET_API_CONSUMER_KEY")
url = "https://getpocket.com/v3/oauth/request"
headers = {
"Content-Type": "application/json; charset=UTF-8",
"X-Accept": "application/json"
}
payload = {
"consumer_key": POCKET_API_CONSUMER_KEY,
"redirect_uri": "https://google.com"
}
response = requests.post(url, json=payload, headers=headers)
# REQUEST TOKEN:
data = response.json()
code = data["code"]
req_url = f"https://getpocket.com/auth/authorize?request_token={code}&redirect_uri=https://www.google.com"
print(f" - Code: {code}")
print(f" - Request URL; go to: {req_url}")
response = False
while response != True:
verification = input(" > Authorized? y/n: ")
if verification == "y":
response = True
print(" - Continuing...")
url = "https://getpocket.com/v3/oauth/authorize"
headers = {
"Content-Type": "application/json; charset=UTF-8",
"X-Accept": "application/json"
}
payload = {
"consumer_key": POCKET_API_CONSUMER_KEY,
"code": code
}
response = requests.post(url, json=payload, headers=headers)
if response.status_code = 200:
print("OK. Application Authorized as:")
res = response.text
res = response.json()
access_token = res["access_token"]
username = res["username"]
print(f" - Access Token: {access_token}")
print(f" - Username: {username}")
print("Completed.")
else:
print(f"[X] Error: {response.status_code}")