openclimatefix / openclimatefix/pv-site-api
Create HTTPX Custom Auth to handle token refresh
@rohanvan123 is already working on this.
Since Apr 11, 2023.
- Dominant language
- Python
- Stars
- 7
- Forks
- 11
- PR merge metrics
- No merged PRs in 30d
Description
After creating a function to get the currently cached Enode access token and another to refresh it if necessary, we'll want to create a custom HTTPx Auth class to handle the logic for actually determining whether our current token needs to be refreshed. The way we do this is by, after someone makes a request to Enode's API, checking the response HTTP status code. If it's a 401, then we know our access token is no longer valid, and we must request another.
The way this is implemented in HTTPx is by creating a custom Auth class, which we'll pass into our HTTPx clients auth argument. See the example under this paragraph in the docs.
- Create the custom Auth class to handle automatically determining token expiration and refreshing it, then re-requesting the resource
Here's how this code looks in TypeScript in our own mock API:
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.