magic-admin-python
magic-admin-python copied to clipboard
Unhelpful error when using wrong api_secret_key
✅ Prerequisites
- [ x] Did you perform a cursory search of open issues? Is this bug already reported elsewhere?
- [ x] Are you running the latest SDK version?
- [x ] Are you reporting to the correct repository (
magic-admin-python
)?
🐛 Description
Was building some code to pull user email out of a token passed from a client in a flask app.
Read the docs wrong and set api_secret_key to the public key for my app instead of the secret key.
When calling User.get_metadata_by_token, I got this trace:
Traceback (most recent call last):
File "/home/ken/.local/lib/python3.8/site-packages/flask/app.py", line 2447, in wsgi_app
response = self.full_dispatch_request()
File "/home/ken/.local/lib/python3.8/site-packages/flask/app.py", line 1952, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/ken/.local/lib/python3.8/site-packages/flask/app.py", line 1821, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/home/ken/.local/lib/python3.8/site-packages/flask/_compat.py", line 39, in reraise
raise value
File "/home/ken/.local/lib/python3.8/site-packages/flask/app.py", line 1950, in full_dispatch_request
rv = self.dispatch_request()
File "/home/ken/.local/lib/python3.8/site-packages/flask/app.py", line 1936, in dispatch_request
return self.view_functionsrule.endpoint
File "/home/ken/flask_test/app.py", line 26, in register_magic_token
response = magic.User.get_metadata_by_token(token.encode('utf-8'))
File "/home/ken/.local/lib/python3.8/site-packages/magic_admin/resources/user.py", line 19, in get_metadata_by_token
return self.get_metadata_by_issuer(self.Token.get_issuer(did_token))
File "/home/ken/.local/lib/python3.8/site-packages/magic_admin/resources/user.py", line 11, in get_metadata_by_issuer
return self.request('get', self.v1_user_info, params={'issuer': issuer})
File "/home/ken/.local/lib/python3.8/site-packages/magic_admin/resources/base.py", line 44, in request
return self._request_client.request(
File "/home/ken/.local/lib/python3.8/site-packages/magic_admin/http_client.py", line 96, in request
return self._parse_and_convert_to_api_response(
File "/home/ken/.local/lib/python3.8/site-packages/magic_admin/http_client.py", line 120, in _parse_and_convert_to_api_response
raise error_class(
magic_admin.error.BadRequestError:
Would be nice to have a better error message here. Can the the Magic() constructor call validate that it's getting a private key?
magic-admin 0.0.4, python3, Ubuntu 20.04
@puntium: Thanks for reporting this. I think it will be a good improvement to add a quick validation on the API key. We will add that in for our next release.