You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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"}}]
The text was updated successfully, but these errors were encountered:
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.
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
while a wrong token would return
[{"error":{"type":1,"address":"/","description":"unauthorized user"}}]
The text was updated successfully, but these errors were encountered: