AzureAD / passport-azure-ad

The code for Passport Azure AD has been moved to the MSAL.js repo. Please open any issues or PRs at the link below.
https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/maintenance/passport-azure-ad
Other
422 stars 176 forks source link

'Error: OIDC strategy requires session support' when using Restify #387

Closed IGZmanuelMartinVivaldi closed 3 years ago

IGZmanuelMartinVivaldi commented 6 years ago

After receiving the POST callback and run passport.authenticate('azuread-openidconnect',... we got this error:

error:   stack:Error: OIDC strategy requires session support. Did you forget to use session middleware such as express-session?
    at SessionContentHandler.findAndDeleteTupleByState (passport-azure-ad\lib\sessionContentHandler.js:44:11)
    at Strategy.collectInfoFromReq (passport-azure-ad\lib\oidcstrategy.js:715:43)
    at async.waterfall (passport-azure-ad\lib\oidcstrategy.js:604:21)
    at fn (passport-azure-ad\node_modules\async\lib\async.js:746:34)
    at passport-azure-ad\node_modules\async\lib\async.js:1213:16
    at passport-azure-ad\node_modules\async\lib\async.js:166:37
    at passport-azure-ad\node_modules\async\lib\async.js:706:43
    at passport-azure-ad\node_modules\async\lib\async.js:167:37
    at Object.async.waterfall (passport-azure-ad\node_modules\async\lib\async.js:710:44)
    at Strategy.authenticateStrategy [as authenticate] (passport-azure-ad\lib\oidcstrategy.js:598:9) transactionId=transactionId required on log

Session packages and OIDCStrategy settings for v2 are included:

server.use(require('./session'));

server.use(passport.initialize());
server.use(passport.session());

    const OIDCStrategy = require('passport-azure-ad').OIDCStrategy;
    const settings = {
        identityMetadata: 'https://login.microsoftonline.com/common/v2.0/.well-known/openid-configuration',
        clientID: config.auth.azuread.clientId,
        redirectUrl: config.auth.azuread.callbackUrl,
        clientSecret: config.auth.azuread.clientSecret,
        responseType: 'id_token',
        responseMode: 'form_post',
        passReqToCallback: false,
        validateIssuer: false,
        scope: ['profile', 'email'] 
    };
    return new OIDCStrategy(settings, azureAdAuthentication);

Any ideas? Thanks in advance.

IGZmanuelMartinVivaldi commented 6 years ago

As the message error clearly explains, 'express-session' is required (maybe 'restify-session' could be used too)

I didn't know express modules could be used with restify.

const expressSession = require('express-session');

server.use(expressSession({ secret: 'keyboard cat', resave: true, saveUninitialized: false }));

Thanks

pkanher617 commented 3 years ago

Closing as this appears resolved. Please open an issue here if you are having further problems.