Beispiel #1
0
    def login_with_credentials_cli(self, username: str, password: str) -> str:
        """
        Pass your username and password to get an access_token for using the API.
        :param username: <str> Phone, email or username
        :param password: <str> Your account password to login
        :return: <str>
        """

        # Give warnings to the user about device-id and token expiration
        warn(
            "IMPORTANT: Take a note of your device-id to avoid 2-factor-authentication for your next login."
        )
        print(f"device-id: {self.__device_id}")
        warn(
            "IMPORTANT: Your Access Token will NEVER expire, unless you logout manually (client.log_out(token)).\n"
            "Take a note of your token, so you don't have to login every time.\n"
        )

        response = self.authenticate_using_username_password(
            username, password)

        # if two-factor error
        if response.get('body').get('error'):
            access_token = self.__two_factor_process_cli(response=response)
            self.trust_this_device()
        else:
            access_token = response['body']['access_token']

        confirm("Successfully logged in. Note your token and device-id")
        print(f"access_token: {access_token}\n"
              f"device-id: {self.__device_id}")

        return access_token
Beispiel #2
0
    def log_out(access_token: str) -> bool:
        """
        Revoke your access_token
        :param access_token: <str>
        :return:
        """

        resource_path = '/oauth/access_token'
        api_client = ApiClient(access_token=access_token)

        api_client.call_api(resource_path=resource_path, method='DELETE')

        confirm(f"Successfully logged out.")
        return True
Beispiel #3
0
    def __trust_this_device(self):

        header_params = {'device-id': self.__device_id}
        resource_path = '/users/devices'

        self.__api_client.call_api(resource_path=resource_path,
                                   header_params=header_params,
                                   method='POST')

        confirm(
            f"Successfully added your device id to the list of the trusted devices."
        )
        print(
            f"Use the same device-id  {self.__device_id}  next time to avoid 2-factor-auth process."
        )
Beispiel #4
0
    def trust_this_device(self, device_id=None):
        """
        Add device_id or self.device_id (if no device_id passed) to the trusted devices on Venmo
        :return:
        """
        device_id = device_id or self.__device_id
        header_params = {'device-id': device_id}
        resource_path = '/users/devices'

        self.__api_client.call_api(resource_path=resource_path,
                                   header_params=header_params,
                                   method='POST')

        confirm(f"Successfully added your device id to the list of the trusted devices.")
        print(f"Use the same device-id: {self.__device_id} next time to avoid 2-factor-auth process.")
Beispiel #5
0
    def login_using_credentials(self, username: str, password: str) -> str:
        """
        Pass your username and password to get an access_token for using the API.
        :param username: <str> Phone, email or username
        :param password: <str> Your account password to login
        :return:
        """

        # Give some warnings to the user for their future benefit
        warn(
            "IMPORTANT: Take a note of your device id to avoid 2-Factor-Authentication for your next login."
        )
        print(f"device-id: {self.__device_id}")
        warn(
            "IMPORTANT: Your Access Token will never expire, unless you logout using it."
            " Take a note of it for your future use or even for logging out, you will need it.\n"
        )

        header_params = {
            'device-id': self.__device_id,
            'Content-Type': 'application/json',
            'Host': 'api.venmo.com'
        }

        body = {
            "phone_email_or_username": username,
            "client_id": "1",
            "password": password
        }
        resource_path = '/oauth/access_token'

        response = self.__api_client.call_api(resource_path=resource_path,
                                              header_params=header_params,
                                              body=body,
                                              method='POST',
                                              ok_error_codes=[81109])

        if response.get('body').get('error'):
            access_token = self.__two_factor_process(response=response)
            self.__trust_this_device()
        else:
            access_token = response['body']['access_token']

        confirm("Successfully logged in.")
        print(f"access_token: {access_token}")

        return access_token