Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions homeassistant/components/frontend/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ async def async_setup(hass, config):

index_view = IndexView(repo_path, js_version, hass.auth.active)
hass.http.register_view(index_view)
hass.http.register_view(AuthorizeView(repo_path, js_version))

@callback
def async_finalize_panel(panel):
Expand Down Expand Up @@ -334,6 +335,35 @@ def reload_themes(_):
hass.services.async_register(DOMAIN, SERVICE_RELOAD_THEMES, reload_themes)


class AuthorizeView(HomeAssistantView):
"""Serve the frontend."""

url = '/auth/authorize'
name = 'auth:authorize'
requires_auth = False

def __init__(self, repo_path, js_option):
"""Initialize the frontend view."""
self.repo_path = repo_path
self.js_option = js_option

async def get(self, request: web.Request):
"""Redirect to the authorize page."""
latest = self.repo_path is not None or \
_is_latest(self.js_option, request)

if latest:
location = '/frontend_latest/authorize.html'
else:
location = '/frontend_es5/authorize.html'

location += '?{}'.format(request.query_string)

return web.Response(status=302, headers={
'location': location
})


class IndexView(HomeAssistantView):
"""Serve the frontend."""

Expand Down
11 changes: 11 additions & 0 deletions tests/components/frontend/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,3 +348,14 @@ async def test_onboarding_load(mock_http_client):
"""Test onboarding component loaded by default."""
resp = await mock_http_client.get('/api/onboarding')
assert resp.status == 200


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?latest&hello=world')
assert resp.url.query_string == 'latest&hello=world'
assert resp.url.path == '/frontend_latest/authorize.html'