mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Add auth/authorize endpoint (#15887)
This commit is contained in:
parent
61901496ec
commit
99c4c65f69
@ -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):
|
||||
@ -334,6 +335,35 @@ def _async_setup_themes(hass, 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."""
|
||||
|
||||
|
@ -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'
|
||||
|
Loading…
x
Reference in New Issue
Block a user