fiznool / passport-oauth2-refresh

A passport.js add-on to provide automatic OAuth 2.0 token refreshing.
MIT License
189 stars 16 forks source link

optional proxy argument added to "use" function #99

Closed liadyacobi closed 1 year ago

liadyacobi commented 3 years ago

Resolves #9 The "use" function now receives a third "agent" parameter which should be the type of HttpsProxyAgent. Added a switch case to handle the case where two parameters (strategy, agent) are sent (without the name param). After the initialization of the current strategy, checks if there is an existing agent, and if there is, it sets it as the agent for the OAuth2 instance.

fiznool commented 3 years ago

Thank you for your contribution. The PR looks great.

Since this issue has resurfaced, I have taken the time to look more broadly at the way that this package deals with the various different OAuth2 configurations that are in the wild. In the past, there have been a few other issues (#3, #10) raised that also require customisation of the OAuth2 config.

In light of these, a more general approach has been introduced with v2.1.0. A new callback setRefreshOAuth2 can now be supplied to customise the OAuth2 adapter that is used to refresh the token. For this particular use case (setting a proxy agent), you should be able to do the following:

const refresh = require('passport-oauth2-refresh');
const HttpsProxyAgent = require('https-proxy-agent');

// ...

refresh.use(strategy, {
  setRefreshOAuth2({ refreshOAuth2 }) {
    refreshOAuth2.setAgent(new HttpsProxyAgent(agentUrl));
    return refreshOAuth2;
  }
});

Please give it a try, and let me know how you get on.

fiznool commented 1 year ago

Closing due to inactivity.