Home > Software engineering >  TypeError: MicrosoftStrategy is not a constructor
TypeError: MicrosoftStrategy is not a constructor

Time:07-06

I'm trying to authenticate my web app with Passport Microsoft. Below is my code:

const MicrosoftStrategy = require('passport-microsoft').MicrosoftStrategy
const passport = require("passport")

passport.use(new MicrosoftStrategy({
    clientID: process.env.REACT_APP_MICROSOFT_APP_ID,
    clientSecret: process.env.REACT_APP_MICROSOFT_APP_SECRET,
    callbackURL: "/auth/microsoft/callback",
    scope: ['user.read'],
    tenant: 'common',
    authorizationURL: 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize',
    tokenURL: 'https://login.microsoftonline.com/common/oauth2/v2.0/token',
    },
    function(accessToken, refreshToken, profile, done) {
        return done(null, profile)
    }
))

passport.serializeUser((user,done) => {
    done(null, user)
})

passport.deserializeUser((user,done) => {
    done(null, user)
})

This is my error: TypeError: MicrosoftStrategy is not a constructor

CodePudding user response:

Per the doc, change this:

const MicrosoftStrategy = require('passport-microsoft').MicrosoftStrategy

to this:

const MicrosoftStrategy = require('passport-microsoft').Strategy;
  • Related