-
Notifications
You must be signed in to change notification settings - Fork 1
/
app_reg.py
30 lines (26 loc) · 1022 Bytes
/
app_reg.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
import requests
import sys
from plistlib import readPlist, writePlist
import webbrowser
address = sys.argv[1]
if address[0:8] != 'https://':
address = 'https://'+address
#put instance address to environmental variables
info = readPlist('info.plist')
info['variables']['instance'] = address
writePlist(info, 'info.plist')
client_name = 'Alfred'
data = {'client_name':client_name,'redirect_uris':'urn:ietf:wg:oauth:2.0:oob','scopes':'read write'}
r = requests.post(address+'/api/v1/apps',data=data)
if r.status_code != 200:
print('error')
else:
rdata = r.json()
client_id = rdata['client_id']
client_secret = rdata['client_secret']
# saving credentials to environmental variables
info['variables']['client_id'] = client_id
info['variables']['client_secret'] = client_secret
writePlist(info, 'info.plist')
#open authentication page
webbrowser.open(address+'/oauth/authorize?client_id='+client_id+'&redirect_uri=urn:ietf:wg:oauth:2.0:oob&response_type=code&scope=read%20write')