-
Notifications
You must be signed in to change notification settings - Fork 0
/
oauth_one.py
executable file
·72 lines (61 loc) · 2.42 KB
/
oauth_one.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
66
67
68
69
70
71
72
#!/usr/bin/python
# We use the code from python OAuth example as the basis to authenticate
# https://gist.github.com/inkedmn/5041037
import socket
import sys
sys.path.append("/static/Data/1/plugins/evernote/lib")
# Python OAuth example
import evernote.edam.userstore.constants as UserStoreConstants
import evernote.edam.type.ttypes as Types
from evernote.api.client import EvernoteClient
plugin_name = "evernote"
plugin_dir = "/static/Data/1/plugins"
plugin_path = plugin_dir + "/" + plugin_name
plugin_file_path = plugin_path + "/files"
plugin_cache_path = plugin_path + "/cache"
plugin_contentHash_path = plugin_path + "/contentHash"
http_loc = "http://" + socket.gethostname() + ".local/plugins/evernote/oauth_two.py"
##
# Helper function to turn query string parameters into a
# Python dictionary
##
def parse_query_string(authorize_url):
uargs = authorize_url.split('?')
vals = {}
if len(uargs) == 1:
raise Exception('Invalid Authorization URL')
for pair in uargs[1].split('&'):
key, value = pair.split('=', 1)
vals[key] = value
return vals
##
# Create an instance of EvernoteClient using your API
# key (consumer key and consumer secret)
# include sandbox=True if operating in sandbox environment
##
client = EvernoteClient(
consumer_key = 'sulph68',
consumer_secret = '45ca10219801d5a5'
)
##
# Provide the URL where the Evernote Cloud API should
# redirect the user after the request token has been
# generated. In this example, localhost is used; note
# that in this example, we're copying the URLs manually
# and that, in production, this URL will need to
# automatically parse the response and send the user
# to the next step in the flow.
##
request_token = client.get_request_token(http_loc)
token_secret = plugin_path + "/token_secret"
f = open(token_secret, "w")
f.write(request_token['oauth_token_secret'])
f.close()
##
# Prompt the user to open the request URL in their browser
##
print "Content-type: text/html\n\n"
print "<html><body>"
print "<script>window.location='" + client.get_authorize_url(request_token) + "';</script>"
print "Evernote OAuth"
print "</body></html>"