Skip to content

Commit f41eb47

Browse files
feat: add identity verification methods to admin.py (#302)
1 parent 0609c0e commit f41eb47

File tree

2 files changed

+72
-2
lines changed

2 files changed

+72
-2
lines changed

duo_client/admin.py

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,11 @@
178178
import time
179179
import urllib.parse
180180
import warnings
181-
from typing import List, Optional
182181
from datetime import datetime, timedelta, timezone
182+
from typing import List, Optional
183183

184184
from . import Accounts, client
185+
185186
USER_STATUS_ACTIVE = "active"
186187
USER_STATUS_BYPASS = "bypass"
187188
USER_STATUS_DISABLED = "disabled"
@@ -3760,6 +3761,49 @@ def update_passport_config(self, enabled_status, enabled_groups: Optional[List[s
37603761
)
37613762
return response
37623763

3764+
def start_idv(self, user_id):
3765+
"""
3766+
Start identity verification process
3767+
3768+
Args:
3769+
user_id (str) - The ID of the Duo user (required)
3770+
3771+
Returns (dict) - Dictionary containing details of IDV process
3772+
"""
3773+
path = f"/admin/v2/identity_verification/{user_id}/start"
3774+
return self.json_api_call(
3775+
"POST",
3776+
path,
3777+
{}
3778+
)
3779+
3780+
def cancel_idv(self, user_id, inquiry_id):
3781+
"""
3782+
Cancel identity verification process
3783+
3784+
Args:
3785+
user_id (str) - The ID of the Duo user (required)
3786+
inquiry_id (str) - The inquiry_id of the request to cancel (required)
3787+
"""
3788+
path = f"/admin/v2/identity_verification/{user_id}/cancel"
3789+
return self.json_api_call(
3790+
"POST",
3791+
path,
3792+
{"inquiry_id": inquiry_id}
3793+
)
3794+
3795+
def get_idv_status(self, user_id):
3796+
"""
3797+
Get the status of a identity verification process
3798+
3799+
Args:
3800+
user_id (str) - The ID of the Duo user (required)
3801+
3802+
Returns (dict) - Dictionary containing details of the identity verification process status
3803+
"""
3804+
path = f"/admin/v2/identity_verification/{user_id}/status"
3805+
return self.json_api_call("GET", path, {})
3806+
37633807

37643808
class AccountAdmin(Admin):
37653809
"""AccountAdmin manages a child account using an Accounts API integration."""
@@ -3849,4 +3893,4 @@ def set_telephony_credits(self, credits):
38493893
}
38503894
return self.json_api_call('POST',
38513895
'/admin/v1/billing/telephony_credits',
3852-
params)
3896+
params)

tests/admin/test_idv.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import json
2+
3+
from .base import TestAdmin
4+
5+
6+
class TestIDV(TestAdmin):
7+
def test_start_idv(self):
8+
""" Test start identity verification process
9+
"""
10+
response = self.client.start_idv('DU012345678901234567')
11+
self.assertEqual(response['uri'], '/admin/v2/identity_verification/DU012345678901234567/start')
12+
13+
def test_get_idv_status(self):
14+
""" Test get identity verification process status
15+
"""
16+
response = self.client.get_idv_status('DU012345678901234567')
17+
(uri, args) = response['uri'].split('?')
18+
self.assertEqual(uri, '/admin/v2/identity_verification/DU012345678901234567/status')
19+
20+
def test_cancel_idv(self):
21+
""" Test cancel identity verification process
22+
"""
23+
response = self.client.cancel_idv('DU012345678901234567', 'inq_PY3skN8RKxPKBPdpbpdtZfHy6rwJ')
24+
body = json.loads(response["body"])
25+
self.assertEqual(response['uri'], '/admin/v2/identity_verification/DU012345678901234567/cancel')
26+
self.assertEqual(body['inquiry_id'], 'inq_PY3skN8RKxPKBPdpbpdtZfHy6rwJ')

0 commit comments

Comments
 (0)