@@ -18,6 +18,9 @@ def __init__ (self, args):
1818 self .url = '/' .join ((args .url .rstrip ('/' ), args .tenant ))
1919 self .url = '/' .join ((self .url , 'oauth2/v2.0' ))
2020 self .state = None
21+ self .use_tls = self .args .use_tls
22+ if self .use_tls is None :
23+ self .use_tls = self .args .redirect_uri .startswith ('https' )
2124 # end def __init__
2225
2326 def check_err (self , r ):
@@ -145,12 +148,13 @@ def do_GET (self):
145148 port = self .args .https_server_port
146149 httpd = HTTPServer (('localhost' , port ), RQ_Handler )
147150
148- httpd .socket = ssl .wrap_socket \
149- ( httpd .socket
150- , keyfile = "/etc/ssl/private/ssl-cert-snakeoil.key"
151- , certfile = "/etc/ssl/certs/ssl-cert-snakeoil.pem"
152- , server_side = True
153- )
151+ if self .use_tls :
152+ httpd .socket = ssl .wrap_socket \
153+ ( httpd .socket
154+ , keyfile = self .args .keyfile
155+ , certfile = self .args .certfile
156+ , server_side = True
157+ )
154158
155159 while not self .request_received :
156160 httpd .handle_request ()
@@ -176,7 +180,13 @@ def do_GET (self):
176180'oauth/client_secret'.
177181
178182By default calling the script with no arguments, the whole process is
179- automatic, but you may want to specify the tenant explicitly using:
183+ automatic. Note that the default TLS key used for the built-in server is
184+ a self-signed certificate which is automatically created on Debian-based
185+ (including Ubuntu) Linux distributions. But the key-file is not readable
186+ for everyone, you need to be in the group 'ssl-cert' or need otherwise
187+ elevated privileges. If you're using a http (as opposed to https)
188+ redirect URI, of course no TLS files are needed. You may want to specify
189+ the tenant explicitly using:
180190
181191 ./oauth-get-token.py -t $TENANT
182192
@@ -237,15 +247,20 @@ def do_GET (self):
237247def main ():
238248 cmd = ArgumentParser \
239249 (epilog = epilog , formatter_class = RawDescriptionHelpFormatter )
240- cmd .add_argument \
241- ( '-T' , '--request-token'
242- , help = "Run only the token-request step"
243- , action = 'store_true'
244- )
245250 cmd .add_argument \
246251 ( '-b' , '--browser'
247252 , help = "Use non-default browser"
248253 )
254+ cmd .add_argument \
255+ ( '--certfile'
256+ , help = "TLS certificate file, default=%(default)s"
257+ , default = "/etc/ssl/certs/ssl-cert-snakeoil.pem"
258+ )
259+ cmd .add_argument \
260+ ( '--keyfile'
261+ , help = "TLS key file, default=%(default)s"
262+ , default = "/etc/ssl/private/ssl-cert-snakeoil.key"
263+ )
249264 cmd .add_argument \
250265 ( '-n' , '--dont-request-tokens'
251266 , dest = 'request_tokens'
@@ -273,11 +288,29 @@ def main ():
273288 , action = 'store_false'
274289 , default = True
275290 )
291+ cmd .add_argument \
292+ ( '-T' , '--request-token'
293+ , help = "Run only the token-request step"
294+ , action = 'store_true'
295+ )
276296 cmd .add_argument \
277297 ( '-t' , '--tenant'
278298 , help = "Tenant part of url, default=%(default)s"
279299 , default = 'organizations'
280300 )
301+ cmd .add_argument \
302+ ( '--use-tls'
303+ , help = "Enforce use of TLS even if the redirect uri is http"
304+ , action = 'store_true'
305+ , default = None
306+ )
307+ cmd .add_argument \
308+ ( '--no-use-tls' , '--dont-use-tls'
309+ , help = "Disable use of TLS even if the redirect uri is https"
310+ , dest = 'use_tls'
311+ , action = 'store_false'
312+ , default = None
313+ )
281314 cmd .add_argument \
282315 ( '-u' , '--url'
283316 , help = "Base url for requests, default=%(default)s"
0 commit comments