athombv / node-homey-oauth2app

This module does the heavy lifting for a Homey App that talks to any OAuth2 Web API.
https://athombv.github.io/node-homey-oauth2app/
5 stars 5 forks source link

More flexibility on checking auth responses #25

Closed Christian-Athom closed 3 years ago

Christian-Athom commented 3 years ago

If we pass the full response to the function, overrides have more flexibility on checking if tokens need to be refreshed, because API builders really like to deviate from the specifications.

WeeJeWel commented 3 years ago

Which extra property did you actually need?

Christian-Athom commented 3 years ago

In this case the body contained the status code to check if the token is still valid

WeeJeWel commented 3 years ago

Well, that's the problem usually. You can only consume the body once. How did you work around this?

Christian-Athom commented 3 years ago

const clonedResponse = response.clone();

const body = await clonedResponse.json();

WeeJeWel commented 3 years ago

Brilliant!