| 
8 | 8 | import hashlib  | 
9 | 9 | import json  | 
10 | 10 | import logging  | 
 | 11 | +import os  | 
11 | 12 | import secrets  | 
12 | 13 | import socket  | 
13 | 14 | import time  | 
@@ -117,7 +118,12 @@ def _request_tokens(  | 
117 | 118 |     ) -> (str | None, str | None):  | 
118 | 119 |         """Web Browser based Authentication."""  | 
119 | 120 |         logger.debug("authenticating with OAuth authorization code flow")  | 
120 |  | -        with AuthHttpServer(self._redirect_uri) as callback_server:  | 
 | 121 | +        with AuthHttpServer(  | 
 | 122 | +            uri=os.environ.get("SNOWFLAKE_OAUTH_SOCKET_ADDRESS", "http://localhost")  | 
 | 123 | +            + ":"  | 
 | 124 | +            + os.environ.get("SNOWFLAKE_OAUTH_SOCKET_PORT", "0"),  | 
 | 125 | +            redirect_uri=self._redirect_uri,  | 
 | 126 | +        ) as callback_server:  | 
121 | 127 |             code = self._do_authorization_request(callback_server, conn)  | 
122 | 128 |             return self._do_token_request(code, callback_server, conn)  | 
123 | 129 | 
 
  | 
@@ -260,7 +266,7 @@ def _do_authorization_request(  | 
260 | 266 |         connection: SnowflakeConnection,  | 
261 | 267 |     ) -> str | None:  | 
262 | 268 |         authorization_request = self._construct_authorization_request(  | 
263 |  | -            callback_server.url  | 
 | 269 | +            callback_server.redirect_uri  | 
264 | 270 |         )  | 
265 | 271 |         logger.debug("step 1: going to open authorization URL")  | 
266 | 272 |         print(  | 
@@ -314,7 +320,7 @@ def _do_token_request(  | 
314 | 320 |         fields = {  | 
315 | 321 |             "grant_type": "authorization_code",  | 
316 | 322 |             "code": code,  | 
317 |  | -            "redirect_uri": callback_server.url,  | 
 | 323 | +            "redirect_uri": callback_server.redirect_uri,  | 
318 | 324 |         }  | 
319 | 325 |         if self._enable_single_use_refresh_tokens:  | 
320 | 326 |             fields["enable_single_use_refresh_tokens"] = "true"  | 
 | 
0 commit comments