Trying to pass OAuth2Strategy from passport-oauth2 but getting error
Uncaught TypeError: util.inherits is not a function
at node_modules/passport-oauth1/lib/strategy.js (strategy.js:116:6)
Below is how I am using this inside a basic example, full code in this repo https://github.com/alex-fusionauth/fusionauth-payload-cms-example. I am setting this up for FusionAuth, but if we can get a solid example this will work for Auth0 and any other OAuth/OIDC provider, maybe we could add to docs as well.
import { CollectionConfig } from 'payload/types'
import {Strategy as OAuth2Strategy} from 'passport-oauth2'
import { Payload } from 'payload';
const Users: CollectionConfig = {
slug: 'users',
auth: {
strategies:[{
name: 'fusionauth',
strategy: async (payload:Payload) => {
return new OAuth2Strategy({
authorizationURL: 'http://localhost:9011/oauth2/authorize',
tokenURL: 'http://localhost:9011/oauth2/token',
clientID: '123-456-789',
clientSecret: 'shhh-its-a-secret',
callbackURL: 'http:localhost:3000/auth/provider/callback',
},
function(accessToken, refreshToken, profile, done) {
payload.logger.info(accessToken)
// User.findOrCreate(..., function(err, user) {
// done(err, user);
// });
})
// return new OpenIDStrategy({
// returnURL: 'http:localhost:3000/auth/openid/return',
// realm: 'http:localhost:3000/'
// },
// function(identifier, done) {
// User.findOrCreate({ openId: identifier }, function(err, user) {
// done(err, user);
// });
// })
}
}]
},
admin: {
useAsTitle: 'email',
},
fields: [
// Email added by default
// Add more fields as needed
],
}
export default Users