mirror of
https://github.com/dani-garcia/vaultwarden.git
synced 2026-05-23 08:32:45 -05:00
[PR #3792] [MERGED] register missing push devices at login #22868
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/dani-garcia/vaultwarden/pull/3792
Author: @stefan0xC
Created: 8/22/2023
Status: ✅ Merged
Merged: 1/30/2024
Merged by: @dani-garcia
Base:
main← Head:register-push-token📝 Commits (1)
6f28af7register missing push devices at login📊 Changes
5 files changed (+60 additions, -21 deletions)
View changed files
📝
src/api/admin.rs(+1 -1)📝
src/api/core/accounts.rs(+18 -11)📝
src/api/identity.rs(+4 -0)📝
src/api/push.rs(+28 -9)📝
src/db/models/device.rs(+9 -0)📄 Description
I've been looking into why enabling push notifications is not enough to get automatic sync to work and why it requires removing the app (or clearing the app data) and as far as I understand this deep dive that is because the endpoint on vaultwarden that registers the token to Bitwarden's Azure Notification Hub is currently only called when the
OnNewToken()method is run. (Which only happens in rare instances, i.e. when installing the app or clearing the app data.)If we save the
push_tokeneven whenPUSH_ENABLED=falsewe could register missing push devices later. I've implemented a crude way of doing it (looking for a user's not yet registered devices on login, once mobile push notifications are enabled).The
push_uuidof a device will only be filled when push is enabled, so we know which push devices have not been registered yet.Note: I'm not sure if there's a way to register the wrong token (which is why I'm skipping devices that have been added before this patch - and also because I don't know what values would be acceptable here). According to the deep dive the mobile clients (both on Android and iOS) should check daily if their token are still correct and will update them if not but I'm not sure what exactly happens in that case. - I'm currently testing what happens if you register the wrong token (if it will start working after 24 hours or if it will keep being broken). If this does not work this whole approach would probably not be viable.
Also since I don't know the API limits of the Bitwarden push relay and I did not want to abuse it (and maybe there's a better way to call the method) I've limited the number of devices that would be processed to
<= 2. I think we could probably improve this a bit but I wanted to get some feedback first if this would be a viable approach. (Instead of calling it on login of a user it migh be better to do that on startup for all unregistered devices. Not really sure what is preferable here...)🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.