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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create HTTP Basic Auth Flow and Token Caching #74

Open
2 of 3 tasks
ericcccsliu opened this issue Apr 11, 2023 · 0 comments · May be fixed by #87
Open
2 of 3 tasks

Create HTTP Basic Auth Flow and Token Caching #74

ericcccsliu opened this issue Apr 11, 2023 · 0 comments · May be fixed by #87
Assignees

Comments

@ericcccsliu
Copy link
Collaborator

ericcccsliu commented Apr 11, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants