mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-07-27 11:19:21 -04:00
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:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user