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

Support refreshing tokens #87

Closed
wants to merge 8 commits into from
Closed

Conversation

DMRobertson
Copy link
Contributor

@DMRobertson DMRobertson commented Apr 26, 2023

Closes #51.

VERY WIP

I am going to force push to this, review at your own peril

@DMRobertson DMRobertson force-pushed the dmr/support-refreshing-tokens branch from a430721 to 51f9855 Compare April 26, 2023 18:18
@DMRobertson DMRobertson force-pushed the dmr/support-refreshing-tokens branch from 42d05d9 to 4968ed2 Compare April 27, 2023 12:14
internal/v2_devices.go Outdated Show resolved Hide resolved
Comment on lines -180 to -184

func (s *Storage) UpdateUserIDForDevice(deviceID, userID string) error {
_, err := s.db.Exec(`UPDATE syncv3_sync2_devices SET user_id = $1 WHERE device_id = $2`, userID, deviceID)
return err
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We now need to know the user_id in order to form a device_id; prior to this it was possible that the user id had not yet been fetched from /whoami.

Come to think of it, we could make the user_id column non null here.

Copy link
Member

Choose a reason for hiding this comment

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

Yes please.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahh, it already is null. It's just that sometimes we put the empty string into this column.

There are six entries in this table with user_id = ''. But they all have since = '' too. I think we ought to drop such devices from the table.


// Either: create a brand-new row for this device, or
// update an existing row for this device with the latest access token.
// TODO: If the latter, we need to tell any existing poller about the new token.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Highlighting this TODO

Comment on lines +170 to +173
func (h *Handler) ensureDeviceIDMigrated(d sync2.Device) error {
if internal.IsNewDeviceID(d.DeviceID) {
return nil
}
Copy link
Contributor Author

@DMRobertson DMRobertson Apr 27, 2023

Choose a reason for hiding this comment

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

Need to write some kind of test for this. E.g.

  • manually insert old-style rows into all relevant tables,
  • run the migration
  • check it succeeds and that we can select the migrated data

Copy link
Member

@kegsay kegsay left a comment

Choose a reason for hiding this comment

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

This looks exactly as I'd expect.

sync2/handler2/handler.go Outdated Show resolved Hide resolved
Comment on lines -180 to -184

func (s *Storage) UpdateUserIDForDevice(deviceID, userID string) error {
_, err := s.db.Exec(`UPDATE syncv3_sync2_devices SET user_id = $1 WHERE device_id = $2`, userID, deviceID)
return err
}
Copy link
Member

Choose a reason for hiding this comment

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

Yes please.

sync3/handler/handler.go Show resolved Hide resolved
@DMRobertson
Copy link
Contributor Author

Closing in favour of newer PRs, #90 for starters.

@DMRobertson DMRobertson closed this May 2, 2023
@DMRobertson DMRobertson deleted the dmr/support-refreshing-tokens branch May 3, 2023 10:48
@DMRobertson DMRobertson restored the dmr/support-refreshing-tokens branch May 3, 2023 10:48
@DMRobertson DMRobertson deleted the dmr/support-refreshing-tokens branch May 30, 2023 11:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Scope the connections to devices and not to a hash of the access token
2 participants