0

Apologies in advance for what might be an obvious question/answer, but I keep scouring the docs and cannot find it.

I know FeathersJS has drop-in strategies for Facebook/Twitter/Github -- I see those in the docs. And I know you can do all sorts of customization authorization strategies. All I am looking to do is authenticate users through a Oauth2 provider that doesnt already have a pre-packaged strategy. I cannot find a working example that does this.

More frustratingly, when I try to follow examples/docs, I get errors coming from the feathersjs npm modules, like:

    <...>/node_modules/@feathersjs/authentication-oauth2/lib/index.js:96
      app.passport.use(name, new Strategy(oauth2Settings, verifier.verify.bind(verifier)));
                             ^
TypeError: Strategy is not a constructor

Does anyone have a working example?

Jared
  • 562
  • 1
  • 6
  • 22

1 Answers1

2

That error means that you didn't pass a Passport oAuth2 strategy. You can set up the general Passport oAuth2 adapter very similar to the example in the documentation:

const oauth2 = require('@feathersjs/authentication-oauth2');
const OAuth2Strategy = require('passport-oauth2').Strategy;

app.configure(oauth2({
  name: 'custom',
  Strategy: OAuth2Strategy,
  authorizationURL: 'https://www.example.com/oauth2/authorize',
  tokenURL: 'https://www.example.com/oauth2/token',
  clientID: EXAMPLE_CLIENT_ID,
  clientSecret: EXAMPLE_CLIENT_SECRET,
  callbackURL: "http://localhost:3000/auth/example/callback"
}));
Daff
  • 43,734
  • 9
  • 106
  • 120
  • thank you! i think i got confused trying to set all the URLs and client info on the strategy, not the oauth2 configuration. – Jared Feb 18 '18 at 01:21