Cloud Updates (#11404)

* Verify stored keys on startup

* Handle Google Assistant messages

* Fix tests

* Don't verify expiration when getting claims

* Remove email based check

* Lint

* Lint

* Lint
This commit is contained in:
Paulus Schoutsen
2018-01-03 10:16:59 -08:00
committed by Pascal Vizeli
parent 86e1d0f952
commit f314b6cb6c
7 changed files with 178 additions and 108 deletions

View File

@@ -1,5 +1,4 @@
"""Package to communicate with the authentication API."""
import hashlib
import logging
@@ -58,11 +57,6 @@ def _map_aws_exception(err):
return ex(err.response['Error']['Message'])
def _generate_username(email):
"""Generate a username from an email address."""
return hashlib.sha512(email.encode('utf-8')).hexdigest()
def register(cloud, email, password):
"""Register a new account."""
from botocore.exceptions import ClientError
@@ -72,10 +66,7 @@ def register(cloud, email, password):
# https://github.com/capless/warrant/pull/82
cognito.add_base_attributes()
try:
if cloud.cognito_email_based:
cognito.register(email, password)
else:
cognito.register(_generate_username(email), password)
cognito.register(email, password)
except ClientError as err:
raise _map_aws_exception(err)
@@ -86,11 +77,7 @@ def confirm_register(cloud, confirmation_code, email):
cognito = _cognito(cloud)
try:
if cloud.cognito_email_based:
cognito.confirm_sign_up(confirmation_code, email)
else:
cognito.confirm_sign_up(confirmation_code,
_generate_username(email))
cognito.confirm_sign_up(confirmation_code, email)
except ClientError as err:
raise _map_aws_exception(err)
@@ -114,10 +101,7 @@ def forgot_password(cloud, email):
"""Initiate forgotten password flow."""
from botocore.exceptions import ClientError
if cloud.cognito_email_based:
cognito = _cognito(cloud, username=email)
else:
cognito = _cognito(cloud, username=_generate_username(email))
cognito = _cognito(cloud, username=email)
try:
cognito.initiate_forgot_password()
@@ -129,10 +113,7 @@ def confirm_forgot_password(cloud, confirmation_code, email, new_password):
"""Confirm forgotten password code and change password."""
from botocore.exceptions import ClientError
if cloud.cognito_email_based:
cognito = _cognito(cloud, username=email)
else:
cognito = _cognito(cloud, username=_generate_username(email))
cognito = _cognito(cloud, username=email)
try:
cognito.confirm_forgot_password(confirmation_code, new_password)