diff --git a/avs_client/refreshtoken/handlers.py b/avs_client/refreshtoken/handlers.py index b67ca8c..384b053 100644 --- a/avs_client/refreshtoken/handlers.py +++ b/avs_client/refreshtoken/handlers.py @@ -8,22 +8,13 @@ class AmazonAlexaServiceLoginHandler(BaseHTTPRequestHandler): def __init__(self, request, client_address, server): + self.callback_url = server.callback_url self.oauth2_manager = helpers.AmazonOauth2RequestManager( client_id=server.client_id, client_secret=server.client_secret, ) super().__init__(request, client_address, server) - @property - def callback_url(self): - # note: ensure the redirect url is whitelisted in the - # 'Allowed Return URLs' section under 'Web Settings' for your - # Security Profile on Amazon Developer Portal. - return 'http://{address}:{port}/callback/'.format( - address=self.server.server_name, - port=self.server.server_port, - ) - def do_GET(self): routes = { '/': self.handle_login, diff --git a/avs_client/refreshtoken/http_server.py b/avs_client/refreshtoken/http_server.py index 2816179..3daed76 100644 --- a/avs_client/refreshtoken/http_server.py +++ b/avs_client/refreshtoken/http_server.py @@ -3,9 +3,11 @@ class AmazonLoginHttpServer(HTTPServer): def __init__( - self, client_id, client_secret, device_type_id, *args, **kwargs + self, client_id, client_secret, device_type_id, callback_url, + *args, **kwargs ): self.client_id = client_id self.client_secret = client_secret self.device_type_id = device_type_id + self.callback_url = callback_url super().__init__(*args, **kwargs) diff --git a/avs_client/refreshtoken/serve.py b/avs_client/refreshtoken/serve.py index 0e3a9ea..e640d46 100755 --- a/avs_client/refreshtoken/serve.py +++ b/avs_client/refreshtoken/serve.py @@ -9,12 +9,17 @@ def serve_forever(address, port, client_id, client_secret, device_type_id): server_address = (address, port) + # ensure the redirect url is whitelisted in the + # 'Allowed Return URLs' section under 'Web Settings' for your + # Security Profile on Amazon Developer Portal. + callback_url = 'http://{}:{}/callback/'.format(*server_address) server = http_server.AmazonLoginHttpServer( server_address=server_address, RequestHandlerClass=handlers.AmazonAlexaServiceLoginHandler, client_id=client_id, client_secret=client_secret, device_type_id=device_type_id, + callback_url=callback_url, ) print('running server on http://{}:{}'.format(*server_address)) server.serve_forever() diff --git a/requirements-dev.txt b/requirements-dev.txt index af63027..d3d4b36 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,4 +1,4 @@ --r requirements.txt +-e . flake8==3.4.0 freezegun==0.3.9 pytest-cov==2.5.1 diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index bfc8a29..0000000 --- a/requirements.txt +++ /dev/null @@ -1,3 +0,0 @@ -hyper==0.7.0 -requests-toolbelt==0.8.0 -requests==2.19.1 diff --git a/scripts/publish-test.sh b/scripts/publish-test.sh index 27d536d..a680026 100755 --- a/scripts/publish-test.sh +++ b/scripts/publish-test.sh @@ -1,6 +1,6 @@ #!/bin/bash rm -rf build rm -rf dist -pandoc --from=markdown --to=rst --output=README.rst README.md +pandoc --from=markdown --to=rst --output=docs/README.rst README.md python setup.py bdist_wheel twine upload -r pypitest dist/* diff --git a/setup.cfg b/setup.cfg index b88034e..282eb5e 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,2 +1,2 @@ [metadata] -description-file = README.md +description-file = docs/README.rst diff --git a/setup.py b/setup.py index 8e0bd40..2293c68 100644 --- a/setup.py +++ b/setup.py @@ -1,29 +1,22 @@ from setuptools import setup, find_packages -import pip.download -from pip.req import parse_requirements - - -def get_requirements(): - requirements = parse_requirements( - 'requirements.txt', - session=pip.download.PipSession() - ) - return [str(r.req) for r in list(requirements)] - setup( name='avs_client', - version='0.7.0', + version='0.7.1', packages=find_packages(exclude=["tests.*", "tests"]), url='https://github.com/richtier/alexa-voice-service-client', license='MIT', author='Richard Tier', author_email='rikatee@gmail.com', description='Python Client for Alexa Voice Service (AVS)', - long_description=open('README.rst').read(), + long_description=open('docs/README.rst').read(), include_package_data=True, - install_requires=get_requirements(), + install_requires=[ + 'hyper>=0.7.0<1.0.0', + 'requests-toolbelt>=0.8.0<1.0.0', + 'requests>=2.19.1<3.0.0', + ], classifiers=[ 'Development Status :: 4 - Beta', 'Environment :: Console', diff --git a/tests/refreshtoken/test_handlers.py b/tests/refreshtoken/test_handlers.py index 40d9d5d..732ac9c 100644 --- a/tests/refreshtoken/test_handlers.py +++ b/tests/refreshtoken/test_handlers.py @@ -16,6 +16,7 @@ def server(): client_id='client-id-here', client_secret='client-secret-here', device_type_id='device-type-id-here', + callback_url='http://localhost:9000/callback/', ) diff --git a/tests/refreshtoken/test_http_server.py b/tests/refreshtoken/test_http_server.py index d6c09ab..9887b7e 100644 --- a/tests/refreshtoken/test_http_server.py +++ b/tests/refreshtoken/test_http_server.py @@ -13,6 +13,7 @@ def test_http_server_passes_args(mock__init__): client_id='client-id-here', client_secret='client-secret-here', device_type_id='device-type-id-here', + callback_url='http://localhost:9000/callback/', ) request = Mock() @@ -25,3 +26,4 @@ def test_http_server_passes_args(mock__init__): assert server.client_id == 'client-id-here' assert server.client_secret == 'client-secret-here' assert server.device_type_id == 'device-type-id-here' + assert server.callback_url == 'http://localhost:9000/callback/'