diff --git a/homeassistant/components/frontend/__init__.py b/homeassistant/components/frontend/__init__.py index 23ae6d485a6..c444ef2e3ca 100644 --- a/homeassistant/components/frontend/__init__.py +++ b/homeassistant/components/frontend/__init__.py @@ -344,11 +344,12 @@ class AuthorizeView(HomeAssistantView): _is_latest(self.js_option, request) if latest: - location = '/frontend_latest/authorize.html' + base = 'frontend_latest' else: - location = '/frontend_es5/authorize.html' + base = 'frontend_es5' - location += '?{}'.format(request.query_string) + location = "/{}/authorize.html{}".format( + base, str(request.url.relative())[15:]) return web.Response(status=302, headers={ 'location': location diff --git a/tests/components/frontend/test_init.py b/tests/components/frontend/test_init.py index e4daf686bfe..b29c8cfb12f 100644 --- a/tests/components/frontend/test_init.py +++ b/tests/components/frontend/test_init.py @@ -294,10 +294,18 @@ async def test_onboarding_load(mock_http_client): async def test_auth_authorize(mock_http_client): """Test the authorize endpoint works.""" - resp = await mock_http_client.get('/auth/authorize?hello=world') - assert resp.url.query_string == 'hello=world' - assert resp.url.path == '/frontend_es5/authorize.html' + resp = await mock_http_client.get( + '/auth/authorize?response_type=code&client_id=https://localhost/&' + 'redirect_uri=https://localhost/&state=123%23456') - resp = await mock_http_client.get('/auth/authorize?latest&hello=world') - assert resp.url.query_string == 'latest&hello=world' - assert resp.url.path == '/frontend_latest/authorize.html' + assert str(resp.url.relative()) == ( + '/frontend_es5/authorize.html?response_type=code&client_id=' + 'https://localhost/&redirect_uri=https://localhost/&state=123%23456') + + resp = await mock_http_client.get( + '/auth/authorize?latest&response_type=code&client_id=' + 'https://localhost/&redirect_uri=https://localhost/&state=123%23456') + + assert str(resp.url.relative()) == ( + '/frontend_latest/authorize.html?latest&response_type=code&client_id=' + 'https://localhost/&redirect_uri=https://localhost/&state=123%23456')