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

Fix/device delegate auth #3

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 7 additions & 2 deletions synapse/api/auth/msc3861_delegated.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,16 +349,21 @@ async def get_user_by_access_token(

# Create the device on the fly if it does not exist
try:
logger.info(f"[DELEGATED AUTH]: Device search started: {user_id.to_string()} - {device_id}")
device = await self.store.get_device(
user_id=user_id.to_string(), device_id=device_id
)
if device is None:
if device:
logger.info(f"[DELEGATED AUTH]: Device found: {device_id}")
else:
logger.info(f"[DELEGATED AUTH]: Device not found, storing new device: {device_id}")
await self.store.store_device(
user_id=user_id.to_string(),
device_id=device_id,
initial_device_display_name="OIDC-native client",
)
except StoreError:
except StoreError as error:
logger.error(f"[DELEGATED AUTH]: Error in device processing: {error}")
await self.store.store_device(
user_id=user_id.to_string(),
device_id=device_id,
Expand Down
30 changes: 15 additions & 15 deletions synapse/handlers/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -760,24 +760,24 @@ async def rehydrate_device(
# token and refresh token to use the dehydrated device's ID and
# copy the old device display name to the dehydrated device,
# and destroy the old device ID
old_device_id = await self.store.set_device_for_access_token(
access_token, device_id
)
await self.store.set_device_for_refresh_token(user_id, old_device_id, device_id)
old_device = await self.store.get_device(user_id, old_device_id)
if old_device is None:
raise errors.NotFoundError()
await self.store.update_device(user_id, device_id, old_device["display_name"])
# can't call self.delete_device because that will clobber the
# access token so call the storage layer directly
await self.store.delete_devices(user_id, [old_device_id])
await self.store.delete_e2e_keys_by_device(
user_id=user_id, device_id=old_device_id
)
# old_device_id = await self.store.set_device_for_access_token(
# access_token, device_id
# )
# await self.store.set_device_for_refresh_token(user_id, old_device_id, device_id)
# old_device = await self.store.get_device(user_id, old_device_id)
# if old_device is None:
# raise errors.NotFoundError()
# await self.store.update_device(user_id, device_id, old_device["display_name"])
# # can't call self.delete_device because that will clobber the
# # access token so call the storage layer directly
# await self.store.delete_devices(user_id, [old_device_id])
# await self.store.delete_e2e_keys_by_device(
# user_id=user_id, device_id=old_device_id
# )

# tell everyone that the old device is gone and that the dehydrated
# device has a new display name
await self.notify_device_update(user_id, [old_device_id, device_id])
await self.notify_device_update(user_id, [device_id])

return {"success": True}

Expand Down
3 changes: 2 additions & 1 deletion synapse/storage/databases/main/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ async def get_device(
desc="get_device",
allow_none=True,
)
logger.info("[DELEGATED AUTH]: get_device(%s, %s) -> %s", user_id, device_id, row)
if row is None:
return None
return {"user_id": row[0], "device_id": row[1], "display_name": row[2]}
Expand Down Expand Up @@ -1789,7 +1790,7 @@ async def delete_devices(self, user_id: str, device_ids: List[str]) -> None:
user_id: The ID of the user which owns the devices
device_ids: The IDs of the devices to delete
"""

logger.info("[DELEGATED AUTH]: Deleting devices %r for user %r", device_ids, user_id)
def _delete_devices_txn(txn: LoggingTransaction) -> None:
self.db_pool.simple_delete_many_txn(
txn,
Expand Down
Loading