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 bare-minimum to generate and store passkey #5

Draft
wants to merge 7 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 21 additions & 0 deletions homeassistant/auth/__init__.py
Expand Up @@ -5,6 +5,7 @@
from collections import OrderedDict
from collections.abc import Mapping
from datetime import timedelta
import logging
import time
from typing import Any, cast

Expand All @@ -23,6 +24,8 @@
EVENT_USER_UPDATED = "user_updated"
EVENT_USER_REMOVED = "user_removed"

_LOGGER = logging.getLogger(__name__)

_MfaModuleDict = dict[str, MultiFactorAuthModule]
_ProviderKey = tuple[str, str | None]
_ProviderDict = dict[_ProviderKey, AuthProvider]
Expand Down Expand Up @@ -66,8 +69,10 @@ async def auth_manager_from_config(
modules = await asyncio.gather(
*(auth_mfa_module_from_config(hass, config) for config in module_configs)
)

else:
modules = []

# So returned auth modules are in same order as config
module_hash: _MfaModuleDict = OrderedDict()
for module in modules:
Expand Down Expand Up @@ -169,6 +174,22 @@ def auth_mfa_modules(self) -> list[MultiFactorAuthModule]:
"""Return a list of available auth modules."""
return list(self._mfa_modules.values())

async def async_get_passkeys(self, user: models.User) -> dict[str, str]:
"""Return a list of passkeys."""

passkeys = []

for module in self._mfa_modules.values():
if module.id == "webauthn":
rv = await module.get_passkeys()

## append passkey to list when user id matches
for key in rv:
if rv[key]["user_id"] == user.id:
passkeys.append({"id": key, "name": "fakename"})

return passkeys

def get_auth_provider(
self, provider_type: str, provider_id: str | None
) -> AuthProvider | None:
Expand Down
8 changes: 8 additions & 0 deletions homeassistant/auth/models.py
Expand Up @@ -129,6 +129,14 @@ class Credentials:
is_new: bool = attr.ib(default=True)


@attr.s(slots=True)
class Passkey:
"""Passkey for user on an auth provider."""

credential_id: str = attr.ib()
credential_public_key: str = attr.ib()


class UserMeta(NamedTuple):
"""User metadata."""

Expand Down