Integrate with the API for adding and getting webauthn creds

This links up the `get_webauthn_credentials_for_user` and
`create_webauthn_credential_for_user` methods of the user api client to
notifications-api.

To send data to the API we need strings to be unicode, so we call
decode('utf-8') on base64 objects.

Co-authored-by: Leo Hemsted <leo.hemsted@digital.cabinet-office.gov.uk>
This commit is contained in:
Katie Smith
2021-05-13 15:54:05 +01:00
parent 362189d562
commit bafcc02b7d
7 changed files with 60 additions and 24 deletions

View File

@@ -192,19 +192,14 @@ class UserApiClient(NotifyAdminAPIClient):
return self.get(endpoint)
def get_webauthn_credentials_for_user(self, user_id):
# TODO: remove when using real API
self.credentials = getattr(self, 'credentials', [])
return self.credentials
endpoint = f'/user/{user_id}/webauthn'
return self.get(endpoint)['data']
def create_webauthn_credential_for_user(self, user_id, credential):
self.credentials = getattr(self, 'credentials', [])
credential_dict = credential.serialize()
endpoint = f'/user/{user_id}/webauthn'
# TODO: remove when using real API
from datetime import datetime
credential_dict['created_at'] = datetime.now().strftime("%Y-%m-%dT%H:%M:%S.%fZ")
self.credentials += [credential_dict]
return self.post(endpoint, data=credential.serialize())
user_api_client = UserApiClient()