-
Notifications
You must be signed in to change notification settings - Fork 0
/
vk_auth.py
35 lines (28 loc) · 994 Bytes
/
vk_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
from json import loads
from urllib.request import urlopen
from urllib.parse import urlencode
from webbrowser import open_new
APP_ID = "6095932"
def get_code():
authorization_request = _construct_authorization_request()
open_new(authorization_request)
def _construct_authorization_request():
params = [
("client_id", APP_ID),
("display", "page"),
("v", "5.64"),
("redirect_uri", "https://api.vk.com/blank.html"),
("response_type", "code"),
("scope", "friends")
]
return 'https://oauth.vk.com/authorize?' + urlencode(params)
def get_token(code):
params = [
("client_id", APP_ID),
("client_secret", "xBjVtvZOkBCsTSZsi58w"),
("redirect_uri", "https://api.vk.com/blank.html"),
("code", code)
]
url = 'https://oauth.vk.com/access_token?' + urlencode(params)
response = urlopen(url).read()
return loads(response.decode())['access_token']