annotate scripts/oauth-get-token.py @ 7089:4d7977d51a4e

make quantity agree in meta description.
author John Rouillard <rouilj@ieee.org>
date Wed, 30 Nov 2022 00:01:48 -0500
parents 8d9a6063cb22
children 8cda8e05c9a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7084
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
1 #!/usr/bin/python3
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
2
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
3 import requests
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
4 import time
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
5 import sys
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
6 import webbrowser
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
7 import ssl
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
8
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
9 from urllib.parse import urlparse, urlencode, parse_qs
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
10 from argparse import ArgumentParser, RawDescriptionHelpFormatter
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
11 from http.server import HTTPServer, BaseHTTPRequestHandler
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
12
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
13 class Request_Token:
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
14
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
15 def __init__ (self, args):
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
16 self.args = args
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
17 self.session = requests.session ()
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
18 self.url = '/'.join ((args.url.rstrip ('/'), args.tenant))
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
19 self.url = '/'.join ((self.url, 'oauth2/v2.0'))
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
20 self.state = None
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
21 # end def __init__
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
22
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
23 def check_err (self, r):
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
24 if not 200 <= r.status_code <= 299:
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
25 raise RuntimeError \
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
26 ( 'Invalid result: %s: %s\n %s'
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
27 % (r.status_code, r.reason, r.text)
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
28 )
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
29 # end def check_err
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
30
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
31 def get_url (self, path, params):
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
32 url = ('/'.join ((self.url, path)))
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
33 url = url + '?' + urlencode (params)
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
34 return url
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
35 # end def get_url
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
36
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
37 def post_or_put (self, method, path, data = None, json = None):
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
38 d = {}
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
39 if data:
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
40 d.update (data = data)
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
41 if json:
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
42 d.update (json = json)
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
43 url = ('/'.join ((self.url, path)))
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
44 r = method (url, **d)
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
45 self.check_err (r)
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
46 return r.json ()
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
47 # end def post_or_put
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
48
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
49 def post (self, path, data = None, json = None):
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
50 return self.post_or_put (self.session.post, path, data, json)
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
51 # end def post
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
52
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
53 def authcode_callback (self, handler):
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
54 msg = ['']
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
55 self.request_received = False
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
56 r = urlparse (handler.path)
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
57 if r.query:
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
58 q = parse_qs (r.query)
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
59 if 'state' in q:
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
60 state = q ['state'][0]
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
61 if state != self.state:
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
62 msg.append \
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
63 ( 'State did not match: expect "%s" got "%s"'
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
64 % (self.state, state)
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
65 )
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
66 elif 'code' not in q:
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
67 msg.append ('Got no code')
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
68 else:
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
69 with open ('oauth/authcode', 'w') as f:
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
70 f.write (q ['code'][0])
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
71 msg.append ('Wrote code to oauth/authcode')
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
72 self.request_received = True
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
73 else:
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
74 msg.append ('No state and no code')
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
75 return 200, '\n'.join (msg).encode ('utf-8')
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
76 # end def authcode_callback
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
77
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
78 def request_authcode (self):
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
79 with open ('oauth/client_id', 'r') as f:
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
80 client_id = f.read ()
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
81 self.state = 'authcode' + str (time.time ())
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
82 params = dict \
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
83 ( client_id = client_id
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
84 , response_type = 'code'
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
85 , response_mode = 'query'
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
86 , state = self.state
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
87 , redirect_uri = self.args.redirect_uri
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
88 , scope = ' '.join
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
89 (( 'https://outlook.office.com/IMAP.AccessAsUser.All'
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
90 , 'https://outlook.office.com/User.Read'
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
91 , 'offline_access'
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
92 ))
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
93 )
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
94 url = self.get_url ('authorize', params)
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
95 print (url)
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
96 if self.args.webbrowser:
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
97 browser = webbrowser.get (self.args.browser)
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
98 browser.open_new_tab (url)
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
99 if self.args.run_https_server:
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
100 self.https_server ()
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
101 if self.args.request_tokens:
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
102 self.request_token ()
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
103 # end def request_authcode
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
104
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
105 def request_token (self):
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
106 with open ('oauth/client_id', 'r') as f:
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
107 client_id = f.read ()
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
108 with open ('oauth/client_secret', 'r') as f:
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
109 client_secret = f.read ().strip ()
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
110 with open ('oauth/authcode', 'r') as f:
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
111 authcode = f.read ().strip ()
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
112 params = dict \
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
113 ( client_id = client_id
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
114 , code = authcode
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
115 , client_secret = client_secret
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
116 , redirect_uri = self.args.redirect_uri
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
117 , grant_type = 'authorization_code'
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
118 # Only a single scope parameter is allowed here
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
119 , scope = ' '.join
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
120 (( 'https://outlook.office.com/User.Read'
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
121 ,
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
122 ))
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
123 )
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
124 result = self.post ('token', data = params)
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
125 with open ('oauth/refresh_token', 'w') as f:
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
126 f.write (result ['refresh_token'])
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
127 with open ('oauth/access_token', 'w') as f:
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
128 f.write (result ['access_token'])
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
129 # end def request_token
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
130
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
131 def https_server (self):
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
132 self.request_received = False
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
133 class RQ_Handler (BaseHTTPRequestHandler):
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
134 token_handler = self
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
135
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
136 def do_GET (self):
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
137 self.close_connection = True
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
138 code, msg = self.token_handler.authcode_callback (self)
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
139 self.send_response (code)
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
140 self.send_header ('Content-Type', 'text/plain')
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
141 self.end_headers ()
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
142 self.wfile.write (msg)
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
143 self.wfile.flush ()
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
144
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
145 port = self.args.https_server_port
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
146 httpd = HTTPServer (('localhost', port), RQ_Handler)
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
147
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
148 httpd.socket = ssl.wrap_socket \
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
149 ( httpd.socket
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
150 , keyfile = "/etc/ssl/private/ssl-cert-snakeoil.key"
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
151 , certfile = "/etc/ssl/certs/ssl-cert-snakeoil.pem"
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
152 , server_side = True
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
153 )
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
154
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
155 while not self.request_received:
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
156 httpd.handle_request ()
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
157 # end def https_server
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
158
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
159 # end class Request_Token
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
160
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
161 epilog = """\
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
162 Retrieving the necessary refresh_token and access_token credentials
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
163 using this script. This asumes you have an email account (plus the
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
164 password) to be used for mail retrieval. And you have registered an
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
165 application in the cloud for this process. The registering of an
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
166 application will give you an application id (also called client id) and
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
167 a tenant in UUID format.
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
168
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
169 First define the necessary TENANT variable:
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
170
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
171 TENANT=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
172
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
173 You need to create a directory named 'oauth' (if not yet existing) and
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
174 put the client id (also called application id) into the file
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
175 'oauth/client_id' and the corresponding secret into the file
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
176 'oauth/client_secret'.
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
177
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
178 By default calling the script with no arguments, the whole process is
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
179 automatic, but you may want to specify the tenant explicitly using:
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
180
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
181 ./oauth-get-token.py -t $TENANT
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
182
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
183 Specifying the tenant explicitly will select the customized company
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
184 login form directly.
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
185
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
186 The automatic process works as follows:
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
187 - First the authorization URL is constructed and pushed to a local
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
188 browser. By default the default browser on that machine is used, you
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
189 can specify a different browser with the -b/--browser option.
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
190 This will show a login form where you should be able to select the
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
191 user to log in with. Log in with the username (the email address) and
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
192 password for that user.
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
193 - A web-server is started on the given port. When you fill out the
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
194 authentication form pushed to the browser, the last step is a redirect
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
195 to an URL that calls back to this webserver. The necessary
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
196 authentication code is transmitted in a query parameter. The code is
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
197 stored into the file 'oauth/authcode'. Using the authcode, the
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
198 refresh_token and access_token are requested and stored in the oauth
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
199 directory.
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
200
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
201 These steps can be broken down into individual steps by options
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
202 disabling one of the steps:
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
203 - The push to the webserver can be disabled with the option
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
204 -w/--dont-push-to-webbrowser -- in that case the URL is printed on
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
205 standard output and must be pasted into the URL input field of a
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
206 browser. It is typically a good idea to use a browser that is
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
207 currently not logged into the company network.
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
208 - The start of the webserver can be disabled with the option
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
209 -s/--dont-run-https-server -- when called with that option no
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
210 webserver is started. You get a redirect to a non-existing page. The
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
211 error-message is something like:
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
212
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
213 This site can’t be reached
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
214
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
215 Copy the URL from the browser into the file 'oauth/authcode'. The URL
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
216 has paramters. We're interested in the 'code' parameter, a very long
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
217 string. Edit the file so that only that string (without the 'code='
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
218 part) is in the file.
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
219 - Requesting the tokens can be disabled with the option
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
220 -n/--dont-request-tokens -- if this option is given, after receiving
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
221 the redirect from the webserver the authentication code is written to
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
222 the file 'oauth/authcode' but no token request is started.
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
223
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
224 If you have either disabled the webserver or the token request, the
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
225 token can be requested (using the file 'oauth/authcode' constructed by
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
226 hand as described above or written by the webserver) with the
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
227 -T/--request-token option:
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
228
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
229 ./oauth-get-token.py [-t $TENANT] -T
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
230
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
231 If successful this will create the 'oauth/access_token' and
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
232 'oauth/refresh_token' files. Note that the authentication code has a
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
233 limited lifetime.
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
234
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
235 """
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
236
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
237 def main ():
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
238 cmd = ArgumentParser \
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
239 (epilog=epilog, formatter_class=RawDescriptionHelpFormatter)
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
240 cmd.add_argument \
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
241 ( '-T', '--request-token'
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
242 , help = "Run only the token-request step"
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
243 , action = 'store_true'
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
244 )
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
245 cmd.add_argument \
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
246 ( '-b', '--browser'
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
247 , help = "Use non-default browser"
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
248 )
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
249 cmd.add_argument \
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
250 ( '-n', '--dont-request-tokens'
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
251 , dest = 'request_tokens'
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
252 , help = "Do not request tokens, just write authcode"
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
253 , action = 'store_false'
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
254 , default = True
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
255 )
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
256 cmd.add_argument \
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
257 ( '-p', '--https-server-port'
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
258 , type = int
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
259 , help = "Port for https server to listen, default=%(default)s"
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
260 " see also -r option, ports must (usually) match."
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
261 , default = 8181
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
262 )
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
263 cmd.add_argument \
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
264 ( '-r', '--redirect-uri'
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
265 , help = "Redirect URI, default=%(default)s"
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
266 , default = 'https://localhost:8181'
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
267 )
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
268 cmd.add_argument \
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
269 ( '-s', '--dont-run-https-server'
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
270 , dest = 'run_https_server'
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
271 , help = "Run https server to wait for connection of browser "
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
272 "to transmit auth code via GET request"
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
273 , action = 'store_false'
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
274 , default = True
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
275 )
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
276 cmd.add_argument \
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
277 ( '-t', '--tenant'
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
278 , help = "Tenant part of url, default=%(default)s"
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
279 , default = 'organizations'
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
280 )
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
281 cmd.add_argument \
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
282 ( '-u', '--url'
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
283 , help = "Base url for requests, default=%(default)s"
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
284 , default = 'https://login.microsoftonline.com'
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
285 )
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
286 cmd.add_argument \
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
287 ( '-w', '--dont-push-to-webbrowser'
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
288 , dest = 'webbrowser'
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
289 , help = "Do not push authcode url into the browser"
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
290 , action = 'store_false'
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
291 , default = True
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
292 )
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
293 args = cmd.parse_args ()
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
294 rt = Request_Token (args)
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
295 if args.request_token:
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
296 rt.request_token ()
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
297 else:
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
298 rt.request_authcode ()
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
299 # end def main
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
300
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
301 if __name__ == '__main__':
8d9a6063cb22 Add oauth-get-token.py script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
302 main ()

Roundup Issue Tracker: http://roundup-tracker.org/