Onboarding to generate auth code (#21777)
This commit is contained in:
1 parent
a0e8543aed
commit
3da0ed9cc7
4 files changed
+44
-2
No files matched your search
@@ -127,6 +127,7 @@ import voluptuous as vol
|
||||
|
||||
from homeassistant.auth.models import User, Credentials, \
|
||||
TOKEN_TYPE_LONG_LIVED_ACCESS_TOKEN
|
||||
from homeassistant.loader import bind_hass
|
||||
from homeassistant.components import websocket_api
|
||||
from homeassistant.components.http import KEY_REAL_IP
|
||||
from homeassistant.components.http.auth import async_sign_path
|
||||
@@ -184,10 +185,18 @@ RESULT_TYPE_USER = 'user'
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def create_auth_code(hass, client_id: str, user: User) -> str:
|
||||
"""Create an authorization code to fetch tokens."""
|
||||
return hass.data[DOMAIN](client_id, user)
|
||||
|
||||
|
||||
async def async_setup(hass, config):
|
||||
"""Component to allow users to login."""
|
||||
store_result, retrieve_result = _create_auth_code_store()
|
||||
|
||||
hass.data[DOMAIN] = store_result
|
||||
|
||||
hass.http.register_view(TokenView(retrieve_result))
|
||||
hass.http.register_view(LinkUserView(retrieve_result))
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ from homeassistant.loader import bind_hass
|
||||
|
||||
from .const import DOMAIN, STEP_USER, STEPS
|
||||
|
||||
DEPENDENCIES = ['http']
|
||||
DEPENDENCIES = ['auth', 'http']
|
||||
|
||||
STORAGE_KEY = DOMAIN
|
||||
STORAGE_VERSION = 1
|
||||
|
||||
@@ -74,6 +74,7 @@ class UserOnboardingView(_BaseOnboardingView):
|
||||
vol.Required('name'): str,
|
||||
vol.Required('username'): str,
|
||||
vol.Required('password'): str,
|
||||
vol.Required('client_id'): str,
|
||||
}))
|
||||
async def post(self, request, data):
|
||||
"""Return the manifest.json."""
|
||||
@@ -98,8 +99,17 @@ class UserOnboardingView(_BaseOnboardingView):
|
||||
await hass.components.person.async_create_person(
|
||||
data['name'], user_id=user.id
|
||||
)
|
||||
|
||||
await self._async_mark_done(hass)
|
||||
|
||||
# Return an authorization code to allow fetching tokens.
|
||||
auth_code = hass.components.auth.create_auth_code(
|
||||
data['client_id'], user
|
||||
)
|
||||
return self.json({
|
||||
'auth_code': auth_code
|
||||
})
|
||||
|
||||
|
||||
@callback
|
||||
def _async_get_hass_provider(hass):
|
||||
|
||||
Reference in new issue
Block a user