Пример #1
0
def grab_keys(filename='duo.conf'):
    config = ConfigParser.RawConfigParser()
    config.read(filename)

    ikey = config.get('duo', 'ikey')
    skey = config.get('duo', 'skey')
    host = config.get('duo', 'host')
    return {'ikey': ikey, 'skey': skey, 'host': host}

duo_keys = grab_keys()
# You can find this information in the integrations section
# where you signed up for Duo.
# instantiate an Auth instance
verify_api = duo_client.Verify(
    ikey=duo_keys['ikey'],
    skey=duo_keys['skey'],
    host=duo_keys['host'],
)
auth_api = duo_client.Auth(
    ikey=duo_keys['ikey'],
    skey=duo_keys['skey'],
    host=duo_keys['host'],
)

# perform a preauth call on a username
def select_user():
    response = ''
    while response != 'q':
        try:
            response = input("Type the user's name in Duo: ")
            devices = auth_api.preauth(username=response)
argv_iter = iter(sys.argv[1:])


def get_next_arg(prompt):
    try:
        return next(argv_iter)
    except StopIteration:
        return input(prompt)


# You can find this information in the integrations section
# where you signed up for Duo.
verify_api = duo_client.Verify(
    ikey=get_next_arg('Verify API integration key ("DI..."): '),
    skey=get_next_arg("integration secret key: "),
    host=get_next_arg('API hostname ("api-....duosecurity.com"): '),
)

# Please use your valid telephone number with country code, area
# code, and 7 digit number. For example: PHONE = '+1-313-555-5555'
PHONE_NUMBER = get_next_arg('phone number ("+1-313-555-5555"): ')

(pin, txid) = verify_api.call(phone=PHONE_NUMBER)
print("Sent PIN: %s" % pin)
state = ""
while state != "ended":
    status_res = verify_api.status(txid=txid)
    print(status_res["event"], "event:", status_res["info"])
    state = status_res["state"]