Skip to content
This repository has been archived by the owner on Dec 28, 2021. It is now read-only.

Commit

Permalink
Fix incorrect callback url generation
Browse files Browse the repository at this point in the history
  • Loading branch information
richtier committed Aug 16, 2018
1 parent dec6f4b commit 4d4b845
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 31 deletions.
11 changes: 1 addition & 10 deletions avs_client/refreshtoken/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion avs_client/refreshtoken/http_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
5 changes: 5 additions & 0 deletions avs_client/refreshtoken/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-r requirements.txt
-e .
flake8==3.4.0
freezegun==0.3.9
pytest-cov==2.5.1
Expand Down
3 changes: 0 additions & 3 deletions requirements.txt

This file was deleted.

2 changes: 1 addition & 1 deletion scripts/publish-test.sh
Original file line number Diff line number Diff line change
@@ -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/*
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[metadata]
description-file = README.md
description-file = docs/README.rst
21 changes: 7 additions & 14 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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='[email protected]',
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',
Expand Down
1 change: 1 addition & 0 deletions tests/refreshtoken/test_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/',
)


Expand Down
2 changes: 2 additions & 0 deletions tests/refreshtoken/test_http_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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/'

0 comments on commit 4d4b845

Please sign in to comment.