-
-
Notifications
You must be signed in to change notification settings - Fork 35.9k
Fix for command_line authentication provider #107419
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
…r as well as creates a person on new user
|
With the following patch existing users are created as a person, too. --- a/homeassistant/auth/providers/command_line.py 2024-02-04 01:41:34.460181490 +0100
+++ b/homeassistant/auth/providers/command_line.py 2024-02-04 01:46:55.952650748 +0100
@@ -118,6 +118,13 @@
username = flow_result["username"].strip().casefold()
users = await self.store.async_get_users()
+ hass = async_get_hass()
+ meta = self._user_meta.get(flow_result["username"], {})
+
+ pretty_name = meta.get("fullname")
+ if not pretty_name:
+ pretty_name = flow_result["username"]
+
for user in users:
if user.name and user.name.strip().casefold() != username:
continue
@@ -127,28 +134,34 @@
for credential in await self.async_credentials():
if credential.data["username"] and credential.data["username"].strip().casefold() == username:
+ coll: person.PersonStorageCollection = hass.data[person.DOMAIN][1]
+ found = False
+ for pers in coll.async_items():
+ if pers.get(person.ATTR_USER_ID) == user.id:
+ found = True
+ break
+
+ if "person" in hass.config.components and not found:
+ await person.async_create_person(hass, pretty_name, user_id=user.id)
+
return credential
cred = self.async_create_credentials({"username": username})
await self.store.async_link_user(user, cred)
return cred
- hass = async_get_hass()
- meta = self._user_meta.get(flow_result["username"], {})
-
provider = _async_get_hass_provider(hass)
await provider.async_initialize()
user = await hass.auth.async_create_user(flow_result["username"], group_ids=[meta.get("group")])
cred = await provider.async_get_or_create_credentials({"username": flow_result["username"]})
- pretty_name = meta.get("fullname")
- if not pretty_name:
- pretty_name = flow_result["username"]
await provider.data.async_save()
await hass.auth.async_link_user(user, cred)
+
if "person" in hass.config.components:
await person.async_create_person(hass, pretty_name, user_id=user.id)
+
# Create new credentials.
return cred
|
| def _async_get_hass_provider(hass): | ||
| """Get the Home Assistant auth provider.""" | ||
| for prv in hass.auth.auth_providers: | ||
| if prv.type == "homeassistant": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if prv.type == "homeassistant": | |
| if prv.type == "command_line": |
apparently I was to fast and this does not actaully work...
|
I suggest adding additional functionality, such as automatically creating a user photo. I have my own LDAP script in Python that authenticates a user and uploads their photo to the |
provide more accurate error Co-authored-by: Sandro <sandro.jaeckel@gmail.com>
This comment was marked as off-topic.
This comment was marked as off-topic.
|
There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days. |
This comment was marked as off-topic.
This comment was marked as off-topic.
|
Because there hasn't been any activity on this PR for quite some time now, I've decided to close it for being stale. Feel free to re-open this PR when you are ready to pick up work on it again 👍 ../Frenck |
Breaking change
Proposed change
Current implementation does not ever match the users that exist in the system. my changes fix that. It also changes new user creation. I mirrored creating a user the way to the frontend does so that you get a person associated with the new user.
Type of change
Additional information
Checklist
ruff format homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all..coveragerc.To help with the load of incoming pull requests: