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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

HueAuthApi: allow token validation #64

Open
mudar opened this issue Jan 22, 2021 · 0 comments
Open

HueAuthApi: allow token validation #64

mudar opened this issue Jan 22, 2021 · 0 comments
Labels
enhancement New feature or request

Comments

@mudar
Copy link

mudar commented Jan 22, 2021

Proposed Change:

Thanks Renee for this great library 馃槂

While migrating my app from the deprecated Philips sdk to Shade, I needed a callback to validate the token stored in the app's sharedPrefs.
This was my temporary solution: I test the authentication by calling the groups endpoint, An invalid token would throw UnauthorizedException. The reason for calling the groups endpoint is because the payload was 2 kb vs 7 kb for the lights.

suspend fun Shade.isConnected(): Boolean = try {
    // Call the api to validate token, regardless of the result object
    groups.getGroups()
    true
} catch (e: UnauthorizedException) {
    false
}

If you think this should be added to Shade, my suggestion for a cleaner solution would be to call a non-existing endpoint and return a boolean based on the error type: Ex: /api/<username>/connected
a valid token would return

[{"error":{"type":4,"address":"/connected","description":"method, GET, not available for resource, /connected"}}]

while a wrong token would return
[{"error":{"type":1,"address":"/","description":"unauthorized user"}}]

@mudar mudar added the enhancement New feature or request label Jan 22, 2021
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

No branches or pull requests

1 participant