-
Notifications
You must be signed in to change notification settings - Fork 315
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
[POC] Support specifying an API key in network requests #1247
Conversation
…ware, and http origin middleware
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
ce5899b
to
3a7576b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exceptional work, Matt 🎉 I think this is all we need for the wallets.
#994 would've been too much work up front so def the right call to add configuration before thinking about that.
👏🏼 for interface SessionAuthDataStore{}
. Regarding the situation of having a client app read from the stacks.js-created session key for non-stacks.js requests, maybe it'd also be helpful to have baked-in callbacks in the middleware? onTokenCreated
, onTokenExpirary
? 🤔 Not entirely sure if this is necessary, was thinking that we might need to call a ReactQuery method or something in some cases, but actually if each request reads from the store, that would also be fine.
Codecov Report
@@ Coverage Diff @@
## master #1247 +/- ##
==========================================
- Coverage 64.11% 63.78% -0.33%
==========================================
Files 124 124
Lines 8600 8657 +57
Branches 1838 1878 +40
==========================================
+ Hits 5514 5522 +8
- Misses 2841 2884 +43
- Partials 245 251 +6
Continue to review full report at Codecov.
|
9adc8a3
to
d13e431
Compare
EDIT: nvm, looks like you've already taken care of this in #1255 :) |
This is a proof-of-concept implementation of adding a
fetch
configuration option to the existingnetwork
object used by almost all functions in stacks.js to perform http requests. This is also related to issue #994 -- while this PR doesn't remove the implicit fetching, it at least makes it configurable.The property is a simple interface matching the standardized
fetch
API:Additionally, two proof-of-concept implementations of API key middleware are also implemented. The first one,
createApiKeyMiddleware
, is a minimalistic function that can be used to specify an API key string. Example usage:A second included middleware implements a proof-of-concept version of dynamic per-session API key authentication. It's located in
fetchApiAuthMiddleware.ts
. This one uses the middlewarepost
callback to check for401 Unauthorized
responses, then requests a new API key, and retries the http request. The example usage is similar:Note that
createApiSessionAuthMiddleware
is an untested proof-of-concept, and the API backend is not yet ready anyway (as of creating this PR). It was implemented as a test to see if the fetch middleware approach is usable in the future for dynamic key authentication.