44import time
55import webbrowser
66import requests
7+ from requests .adapters import HTTPAdapter , Retry
78from pathlib import Path
89import click
910import configparser
@@ -50,6 +51,7 @@ def __init__(self, tenant_name: str, tenant_alias: str, cli: any, federation_pro
5051 self .alias = tenant_alias
5152 self .base_url = f'https://{ Britive .parse_tenant (tenant_name )} '
5253 self .federation_provider = federation_provider
54+ self .session = None
5355
5456 # not sure if we really need 32 random bytes or if any random string would work
5557 # but the current britive-cli in node.js does it this way so it will be done the same
@@ -58,10 +60,29 @@ def __init__(self, tenant_name: str, tenant_alias: str, cli: any, federation_pro
5860 self .auth_token = b64_encode_url_safe (bytes (hashlib .sha512 (self .verifier .encode ('utf-8' )).digest ()))
5961 self .credentials = self .load () or {}
6062
63+ def _setup_requests_session (self ):
64+ self .session = requests .Session ()
65+ retries = Retry (total = 5 , backoff_factor = 1 , status_forcelist = [429 , 500 , 502 , 503 , 504 ])
66+ self .session .mount ('https://' , HTTPAdapter (max_retries = retries ))
67+
68+ # allow the disabling of TLS/SSL verification for testing in development (mostly local development)
69+ if os .getenv ('BRITIVE_NO_VERIFY_SSL' ) and '.dev.' in self .tenant :
70+ # turn off ssl verification
71+ self .session .verify = False
72+ # wipe these due to this bug: https://github.com/psf/requests/issues/3829
73+ os .environ ['CURL_CA_BUNDLE' ] = ""
74+ os .environ ['REQUESTS_CA_BUNDLE' ] = ""
75+ # disable the warning message
76+ import urllib3
77+ urllib3 .disable_warnings (urllib3 .exceptions .InsecureRequestWarning )
78+
6179 def perform_interactive_login (self ):
6280 self .cli .print (f'Performing interactive login against tenant { self .tenant } .' )
6381 url = f'{ self .base_url } /login?token={ self .auth_token } '
6482
83+ # establish a requests session which will be used in retrieve_tokens()
84+ self ._setup_requests_session ()
85+
6586 try :
6687 webbrowser .get ()
6788 webbrowser .open (url )
0 commit comments