-
-
Notifications
You must be signed in to change notification settings - Fork 299
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
Export default request handler from rest package #3403
Comments
Hmm, the use case sounds more like some good middleware. Perhaps its time to actually implement that haha |
Though, it wouldnt be a bad feature to just add either... |
Ill reorganize things to move more of the logic to the utils package which should make it more reusable. If you could whip up a small sample of how that retry logic would work, i could incorporate it into that as well |
I encountered the same issue, I was able to work around it by writing an asynchronous function that renews and returns the token and passing it as the token when constructing the let token: {
access_token: string,
refresh_token: string,
expires_in: number,
expires_at: number // Non-standard field calculated at time token is issued
} = {...};
async function refresh_token() {
token = ...; // Refresh using `refreshTokenGrantRequest` from `oauth4webapi`
token.expires_at = token.expires_in + (Date.now() / 1000);
}
async function get_token() {
if(token.expires_at - (Date.now() / 1000) < 0) {
token = await refresh_token();
}
return token.access_token.
}
const gl = new Gitlab({
oauthToken: get_token
}); |
Hey, sorry for leaving this issue unattended, had a busy month. My usecase is a bit different than the default refresh token flow defined in RFC 6749. I'm using a third party integration which abstracts using refresh tokens, and it doesn't provide me with an expiration date either, so I need a custom flow to reauthorize. Not sure what the best approach is at this |
hmm, how do you know when to refresh? I could expose a handler of some sort, that would be executed when an expiry happens, but hmm you said there is not expiry date. The latest stuff ive been working on exposes everything adequately, and allows you to replace the handler either in pieces or its entirety. I havent added the refresh flow as of yet since im not sure the best way to do this that isnt highly restrictive. |
Description
I would like to be able to reuse the default request handler defined in packages/rest/src/Requester.ts to allow extending the default behaviour of the client.
Use case: need to add retry logic when access token expires, so I can refresh the token.
This would sort-of solve issue #279
Proposal
Export the defaultRequestHandler and defaultRequestOptions from
@gitbeaker/rest
package.Checklist
The text was updated successfully, but these errors were encountered: