Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

help needed: using open-id-client with passport #12

Closed
eman-moh opened this issue Feb 1, 2017 · 4 comments
Closed

help needed: using open-id-client with passport #12

eman-moh opened this issue Feb 1, 2017 · 4 comments

Comments

@eman-moh
Copy link

eman-moh commented Feb 1, 2017

When I run my express app, I get this error:
TypeError: Cannot read property 'callbackParams' of undefined at OpenIDConnectStrategy.authenticate (../grant/node_modules/openid-client/lib/passport_strategy.js:63:31) at attempt (../grant/node_modules/passport/lib/middleware/authenticate.js:348:16)
I'm including code snippet from my app.js file:

exports.appPromise = new Promise(resolve => {
  Issuer.discover('xxxxxxx')
    .then(function (identityIssuer) {
      app.use(bodyParser.json());
      app.use(bodyParser.urlencoded({
        extended: false
      }));
      app.use(cookieParser());
      app.use(express.static(path.join(__dirname, 'public')));
      app.use(cookieSession({
        secret: 'xxxx',
        resave: false,
        saveUninitialized: true,
        cookie: {
          secure: true
        }
      }));
      let client = new identityIssuer.Client({
        client_id: 'emailAPI',
        client_secret: 'xx'
      });
      passport.use('oidc', new Strategy(client, (tokenset, userinfo, done) => {
        console.log('tokenset', tokenset);
        console.log('access_token', tokenset.access_token);
        console.log('id_token', tokenset.id_token);
        console.log('claims', tokenset.claims);
        console.log('userinfo', userinfo);
        return done(null, false);
      }));
      app.use(passport.initialize());
      app.use('/users', passport.authenticate('oidc'), function (req, res) {
        console.log('httpOptions %j', Issuer.defaultHttpOptions);
        res.send(client.authorizationUrl({
          redirect_uri: 'xxx',
          scope: 'openid email'
        }));
      });
      resolve(app);
    });
});
@panva
Copy link
Owner

panva commented Feb 1, 2017

got it reproduced

@panva panva closed this as completed in 55d44e5 Feb 1, 2017
@panva
Copy link
Owner

panva commented Feb 1, 2017

Just for reference, my server file.

'use strict';

const Issuer = require('.').Issuer;
const Strategy = require('.').Strategy;

const app = require('express')();
const passport = require('passport');
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser');
const cookieSession = require('cookie-session');

Issuer.discover('https://guarded-cliffs-8635.herokuapp.com').then(function (issuer) {
  return issuer.Client.register({
    redirect_uris: ['http://lvh.me:3000/users'],
  });
}).then(function (client) {
  client.CLOCK_TOLERANCE = 5;
  app.use(bodyParser.urlencoded());
  app.use(cookieParser());
  app.use(cookieSession({ secret: 'foo', resave: false, saveUnitialized: true, cookie: { secure: false } }));

  passport.use('oidc', new Strategy(client, (tokenset, done) => {
    console.log(tokenset);
    return done(null, false);
  }));

  app.use(passport.initialize());
  app.use('/users', passport.authenticate('oidc'), function (req, res) {
    res.send('foo');
  });

  app.listen(3000);
});

@floydprice
Copy link

When i run the server file above i get a state miss match.

@panva
Copy link
Owner

panva commented Aug 1, 2017

@floydprice too many moving pieces to tell what's wrong, are you getting a state back on your response? can you see it in the authorization response?

@github-actions github-actions bot locked and limited conversation to collaborators Apr 7, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants