pyicloud
pyicloud copied to clipboard
Document about 2FA
I think the document can be modified to show how to support 2FA verification code.
api = PyiCloudService('[email protected]')
if api.requires_2sa:
import click
print "Two-step authentication required. Your trusted devices are:"
devices = api.trusted_devices
devices_count = len(devices)
for i, device in enumerate(devices):
print " %s: %s" % (i, device.get('deviceName',
"SMS to %s" % device.get('phoneNumber')))
print(" %s: Enter two-factor authentication code" % devices_count)
device = click.prompt('Which device would you like to use?', default=0)
if device == devices_count:
# We're using the 2FA code that was automatically sent to the user's device,
# so can just use an empty dict()
device = dict()
else:
device = devices[device]
if not api.send_verification_code(device):
print "Failed to send verification code"
sys.exit(1)
code = click.prompt('Please enter validation code')
if not api.validate_verification_code(device, code):
print "Failed to verify verification code"
sys.exit(1)