Description
Enode requires us to obtain an access token from their API in order to use the main endpoints in their API. The way they do this is through "Basic" HTTP Authentication scheme. What this involves is sending our Enode client credentials (client ID as username and client secret as password), over to Enode's access token fetch endpoint via that auth scheme. Fortunately, the HTTP Python library we'll be using (https://www.python-httpx.org/), handles Basic authentication for us (https://www.python-httpx.org/quickstart/#authentication).
Once we've got a token, it makes sense to continue to reuse it over the course of the hour it's useable, until it must be refreshed. To do this, we'll store the token in OCF's database under a new table, found here. This table has a helper function you can use to actually get the token without accessing SQL models.
- Add the python library httpx using poetry.
- Create a function to make a request to Enode to get an API access token - see
- Create a function to get the token from the database, or, if it doesn't exist, call your function above, then store it back in the DB.
See here for our current implementation in TypeScript.