def keyring_get_password(username): keyring_impl = keyring.get_keyring() verbose("Note: will use the backend: '{0}'".format(keyring_impl)) password = keyring.get_password('cbas', username) if not password: info("No password found in keychain, please enter it now to store it.") password = prompt_get_password(username) keyring.set_password('cbas', username, password) return password
def obtain_access_token(config, password): info("Will now attempt to obtain an JWT...") auth_request_data = {'client_id': 'jumpauth', 'username': config.username, 'password': password, 'grant_type': 'password'} auth_url = get_auth_url(config) auth_response = requests.post(auth_url, auth_request_data) if auth_response.status_code not in [200, 201]: log.info("Authentication failed: {0}". format(auth_response.json().get("error"))) auth_response.raise_for_status() else: log.info("Authentication OK!") # TODO bail out if there was no access token in the answer access_token = auth_response.json()['access_token'] info("Access token was received.") verbose("Access token is:\n'{0}'".format(access_token)) return access_token
def obtain_access_token(config, password): info("Will now attempt to obtain an JWT...") auth_request_data = { 'client_id': 'jumpauth', 'username': config.username, 'password': password, 'grant_type': 'password' } auth_url = get_auth_url(config) auth_response = requests.post(auth_url, auth_request_data) if auth_response.status_code not in [200, 201]: log.info("Authentication failed: {0}".format( auth_response.json().get("error"))) auth_response.raise_for_status() else: log.info("Authentication OK!") # TODO bail out if there was no access token in the answer access_token = auth_response.json()['access_token'] info("Access token was received.") verbose("Access token is:\n'{0}'".format(access_token)) return access_token