-
Notifications
You must be signed in to change notification settings - Fork 34
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
feat(op): allow custom interceptor for authenticated client #422
Conversation
🦋 Changeset detectedLatest commit: 07546fa The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
✅ Deploy Preview for openpayments-preview canceled.
|
80b0518
to
f6033f0
Compare
f6033f0
to
d919c87
Compare
runWhen: (config: InternalAxiosRequestConfig) => | ||
config.method?.toLowerCase() === 'post' || | ||
!!(config.headers && config.headers['Authorization']) |
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.
I think because we are specifying POST with Authorization runWhen
here (and not leaving it up to the caller), we should probably make the requestInterceptor
name more explicit? like authenticatedRequestInterceptor
or something along those lines.
@@ -0,0 +1,5 @@ | |||
--- | |||
'@interledger/open-payments': minor |
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.
Im trying to think of a better naming when it comes to the "experimental" nature of the change. Maybe I'm over-complicating this though
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.
Final comment
axiosInstance.interceptors.request.use( | ||
args.authenticatedRequestInterceptor, | ||
undefined, | ||
{ | ||
runWhen: (config: InternalAxiosRequestConfig) => | ||
config.method?.toLowerCase() === 'post' || | ||
!!(config.headers && config.headers['Authorization']) | ||
} | ||
) |
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.
I think the only thing that would be nice is a small test for this to check that the interceptor was added. I think you can use
createCustomAxiosInstance({
requestTimeoutMs: 0,
authenticatedRequestInterceptor: interceptor
}).interceptors.request['handlers'][0]
to get a reference to the interceptor
Changes proposed in this pull request
Allow a custom request interceptor to be passed rather than the private key and key ID. This custom interceptor will then be registered and replace the built-in interceptor for generating signatures.
Context
Closes #412.