def get_client(options): client_id = client_secret = ip = None if options.client_id is not None and options.client_secret is not None: client_id = options.client_id client_secret = options.client_secret region = options.region else: if os.path.isfile('onelogin.sdk.json'): json_data = open('onelogin.sdk.json').read() data = json.loads(json_data) if 'client_id' in data.keys() and 'client_secret' in data.keys(): client_id = data['client_id'] client_secret = data['client_secret'] region = data.get('region', 'us') ip = data.get('ip', None) if client_id is None or client_secret is None: raise Exception("OneLogin Client ID and Secret are required") client = OneLoginClient(client_id, client_secret, region) if ip: client.ip = ip client.prepare_token() if client.error == 401 or client.access_token is None: raise Exception( "Invalid client_id and client_secret. Access_token could not be retrieved" ) return client
def get_client(options): client_id = client_secret = ip = json_data = None region = 'us' client_file_name = 'onelogin.sdk.json' if options.client_id is not None and options.client_secret is not None: client_id = options.client_id client_secret = options.client_secret region = options.region ip = options.ip else: if options.config_file_path is not None and os.path.isfile( os.path.join(options.config_file_path, client_file_name)): json_data = open( os.path.join(options.config_file_path, client_file_name)).read() elif os.path.isfile(client_file_name): json_data = open(client_file_name).read() elif os.path.isfile( os.path.expanduser('~') + '/.onelogin/' + client_file_name): json_data = open( os.path.expanduser('~') + '/.onelogin/' + client_file_name).read() if json_data is not None: data = json.loads(json_data) if 'client_id' in data.keys() and 'client_secret' in data.keys(): client_id = data['client_id'] client_secret = data['client_secret'] if 'region' in data.keys() and data['region']: region = data['region'] if 'ip' in data.keys() and data['ip']: ip = data['ip'] if not client_id or not client_secret: raise Exception("OneLogin Client ID and Secret are required") client = OneLoginClient(client_id, client_secret, region) client.api_configuration["assertion"] = options.saml_api_version if ip: client.ip = ip client.prepare_token() if client.error == 401 or client.access_token is None: raise Exception( "Invalid client_id and client_secret. Access_token could not be retrieved" ) return client