capless / warrant

Python library for using AWS Cognito. With support for SRP.
Apache License 2.0
468 stars 192 forks source link

register function error, TypeError #115

Open koorukuroo opened 6 years ago

koorukuroo commented 6 years ago

There are TypeError for register like #69

I try to it in branch of master, develop, features... But these have same error.

u.add_base_attributes(email='test@gmail.com')
u.add_custom_attributes(state='virginia', city='Centreville')
u.register(username='xxx', password='qwerty234@$')

Error Message

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-7-1104a483b338> in <module>()
     14 u.add_base_attributes(email='test@gmail.com')
     15 u.add_custom_attributes(state='virginia', city='Centreville')
---> 16 u.register(username='xxx', password='qwerty234@$')

~/anaconda3/envs/A/lib/python3.6/site-packages/warrant/__init__.py in register(self, username, password, attr_map)
    308             'UserAttributes': cognito_attributes
    309         }
--> 310         self._add_secret_hash(params, 'SecretHash')
    311         response = self.client.sign_up(**params)
    312 

~/anaconda3/envs/A/lib/python3.6/site-packages/warrant/__init__.py in _add_secret_hash(self, parameters, key)
    626         if self.client_secret is not None:
    627             secret_hash = AWSSRP.get_secret_hash(self.username, self.client_id,
--> 628                                                  self.client_secret)
    629             parameters[key] = secret_hash
    630 

~/anaconda3/envs/A/lib/python3.6/site-packages/warrant/aws_srp.py in get_secret_hash(username, client_id, client_secret)
    169     @staticmethod
    170     def get_secret_hash(username, client_id, client_secret):
--> 171         message = bytearray(username + client_id, 'utf-8')
    172         hmac_obj = hmac.new(bytearray(client_secret, 'utf-8'), message, hashlib.sha256)
    173         return base64.standard_b64encode(hmac_obj.digest()).decode('utf-8')

TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'
BabyDino commented 6 years ago

I am experiencing the same issue.

Found the error @koorukuroo

u = Cognito('eu-west-1_xxxx', 'xxxx', client_secret='xxxxx',username='test@test.com')

u.add_base_attributes(email='test@test.com',locale='nl_NL',given_name='Test',family_name='Test')

u.register('test@test.com','Test1234!')

You have to add the username to Cognito() as well.

dperconti commented 5 years ago

I'm experiencing the same issue as well. @BabyDino or @koorukuroo - were either of you able to figure out the issue/solution for this?

BabyDino commented 5 years ago

See my code above, did you add username='test@test.com'?

dperconti commented 5 years ago

I ended up creating a client without a secret (still without username), which is now working. Thanks!