Next-auth: Example for generic OAuth2?

Created on 8 Jun 2018  路  4Comments  路  Source: nextauthjs/next-auth

Hi,

After adding a generic passport-oauth2 provider in next-auth.providers.js, I'm running into this error on /auth/oauth/mycoolprovider:

TypeError: strategy.authenticate is not a function
    at attempt (/Users/joshkadis/Repos/themostlaps_v2/node_modules/passport/lib/middleware/authenticate.js:361:16)
    at authenticate (/Users/joshkadis/Repos/themostlaps_v2/node_modules/passport/lib/middleware/authenticate.js:362:7)
    at Layer.handle [as handle_request] (/Users/joshkadis/Repos/themostlaps_v2/node_modules/express/lib/router/layer.js:95:5)
    at next (/Users/joshkadis/Repos/themostlaps_v2/node_modules/express/lib/router/route.js:137:13)
# etc., etc...

It seems like Passport can't find the function registered for the named authentication strategy. Can you provide some documentation for this step from AUTHENTICATE.md?

Add a field to your User model (in 'index.js') with the name of the provider

Thanks for the rad library!

documentation question

Most helpful comment

Turns out that the above error was happening because Passport was registering the strategy as oauth2 rather than as the providerName from my next-auth.providers.js. I.e. Passport couldn't find a strategy called strava when I did it this way:

{
  providerName: 'Strava',
  Strategy: OAuth2Strategy.Strategy,
}

Changing the providerName to OAuth2 would have worked although I ended up using an open source Passport strategy for Strava.

Could still use a tip on the adding a field to the User model thing though. Thanks!

All 4 comments

Thanks, sorry I haven't been able to answer this before now, I'll try and respond tomorrow!

Turns out that the above error was happening because Passport was registering the strategy as oauth2 rather than as the providerName from my next-auth.providers.js. I.e. Passport couldn't find a strategy called strava when I did it this way:

{
  providerName: 'Strava',
  Strategy: OAuth2Strategy.Strategy,
}

Changing the providerName to OAuth2 would have worked although I ended up using an open source Passport strategy for Strava.

Could still use a tip on the adding a field to the User model thing though. Thanks!

Thank you for the feeedback and follow up. Version 2.0 works much better with generic oAuth services, and is much easier to configure.

The documentation is a work in progress however, this is a good reminder to do that, moving this issue into milestone for 2.0.

This is now provided in the documentation of 2.0.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ryanditjia picture ryanditjia  路  3Comments

ryanbahan picture ryanbahan  路  3Comments

readywater picture readywater  路  3Comments

ghoshnirmalya picture ghoshnirmalya  路  3Comments

iaincollins picture iaincollins  路  3Comments