Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add context to login flow #15914

Merged
merged 4 commits into from
Aug 13, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion homeassistant/auth/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ async def _async_create_login_flow(self, handler, *, context, data):
"""Create a login flow."""
auth_provider = self._providers[handler]

return await auth_provider.async_credential_flow()
return await auth_provider.async_credential_flow(context)

async def _async_finish_login_flow(self, result):
"""Result of a credential login flow."""
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/auth/providers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def async_create_credentials(self, data):

# Implement by extending class

async def async_credential_flow(self):
async def async_credential_flow(self, context):
"""Return the data flow for logging in with auth provider."""
raise NotImplementedError

Expand Down
2 changes: 1 addition & 1 deletion homeassistant/auth/providers/homeassistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ async def async_initialize(self):
self.data = Data(self.hass)
await self.data.async_load()

async def async_credential_flow(self):
async def async_credential_flow(self, context):
"""Return a flow to login."""
return LoginFlow(self)

Expand Down
2 changes: 1 addition & 1 deletion homeassistant/auth/providers/insecure_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class InvalidAuthError(HomeAssistantError):
class ExampleAuthProvider(AuthProvider):
"""Example auth provider based on hardcoded usernames and passwords."""

async def async_credential_flow(self):
async def async_credential_flow(self, context):
"""Return a flow to login."""
return LoginFlow(self)

Expand Down
2 changes: 1 addition & 1 deletion homeassistant/auth/providers/legacy_api_password.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class LegacyApiPasswordAuthProvider(AuthProvider):

DEFAULT_TITLE = 'Legacy API Password'

async def async_credential_flow(self):
async def async_credential_flow(self, context):
"""Return a flow to login."""
return LoginFlow(self)

Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/auth/login_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ async def post(self, request, data):
handler = data['handler']

try:
result = await self._flow_mgr.async_init(handler)
result = await self._flow_mgr.async_init(handler, context={})
except data_entry_flow.UnknownHandler:
return self.json_message('Invalid handler specified', 404)
except data_entry_flow.UnknownStep:
Expand Down
5 changes: 4 additions & 1 deletion homeassistant/data_entry_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def async_progress(self) -> List[Dict]:
'flow_id': flow.flow_id,
'handler': flow.handler,
'source': flow.source,
'context': flow.context,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why expose this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically same purpose as source. In trusted networks auth provider, need to verify current IP address is same as context. I can remove above source exposure.

} for flow in self._progress.values()]

async def async_init(self, handler: Callable, *, context: Dict = None,
Expand All @@ -57,6 +58,7 @@ async def async_init(self, handler: Callable, *, context: Dict = None,
flow.hass = self.hass
flow.handler = handler
flow.flow_id = uuid.uuid4().hex
flow.context = context
self._progress[flow.flow_id] = flow

return await self._async_handle_step(flow, flow.init_step, data)
Expand Down Expand Up @@ -122,11 +124,12 @@ class FlowHandler:
flow_id = None
hass = None
handler = None
source = None
cur_step = None
context = None

# Set by _async_create_flow callback
init_step = 'init'
source = None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this since it's in context now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was just lazy to change... will do it.


# Set by developer
VERSION = 1
Expand Down
3 changes: 2 additions & 1 deletion tests/components/config/test_config_entries.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,8 @@ def async_step_account(self, user_input=None):
{
'flow_id': form['flow_id'],
'handler': 'test',
'source': 'hassio'
'source': 'hassio',
'context': {'source': 'hassio'}
}
]

Expand Down