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

Automatically accept TOU #550

Merged
merged 1 commit into from
Jun 18, 2023
Merged

Automatically accept TOU #550

merged 1 commit into from
Jun 18, 2023

Conversation

FokkeZB
Copy link
Contributor

@FokkeZB FokkeZB commented Jun 16, 2023

Sometimes, login can ask to accept terms, and will not return the user ID we need, nor respond to later requests for data until the terms have been accepted.

This PR handles that by automatically accepting the terms.

Closes #452

Copy link
Contributor Author

@FokkeZB FokkeZB left a comment

Choose a reason for hiding this comment

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

Self-review

@@ -509,7 +565,7 @@ private struct LibreLinkResponseGlucose: Codable {
// MARK: - LibreLinkResponseUser

private struct LibreLinkResponseUser: Codable {
let id: String
Copy link
Contributor Author

Choose a reason for hiding this comment

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

When prompted for terms, the id is missing.

@@ -188,7 +188,20 @@ class LibreLinkUpConnection: SensorBluetoothConnection, IsSensor {
if lastLogin == nil || lastLogin!.authExpires <= Date() {
DirectLog.info("LibreLinkUp processLogin, starts working, \(Date().debugDescription)")

let loginResponse = try await login(apiRegion: apiRegion)
var loginResponse = try await login(apiRegion: apiRegion)
if loginResponse.status == 4 {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

AFAIK a status of 4 means we need to accept terms. I could also type the step object so that I could do loginResponse.data.step.type == "tou" here, but this works.

throw LibreLinkError.missingUserOrToken
}

loginResponse = try await tou(apiRegion: apiRegion, authToken: authToken)
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 do need the token.

if let apiRegion = apiRegion {
urlString = "https://api-\(apiRegion).libreview.io/auth/continue/tou"
} else {
urlString = "https://api.libreview.io/auth/continue/tou"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

All we need is a POST to this endpoint, and pass along the token.

DirectLog.info("LibreLinkUp tou, response: \(String(data: data, encoding: String.Encoding.utf8))")

if statusCode == 200 {
return try decode(LibreLinkResponse<LibreLinkResponseLogin>.self, data: data)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The response is identical to login.

@creepymonster
Copy link
Owner

Thank you so much <3, I haven't had enough time the last few months, I'll have a look at the PR. I will do that in the next few days.

Many greetings
Reimar

@creepymonster creepymonster merged commit 1e9ab9e into creepymonster:main Jun 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Give warning when you need to accept ToS from Libre Link Up
2 participants