2

I must be missing something very obvious on this one.

I've been trying to trust/follow the official docs on this one but I'm noticing I'm not actually using that whole 'bearerStrategy' I'm defining anywhere. If I try to swap out oauth-bearer with bearerStrategy I'm getting the exact same result.

Setup:

const passport = require('passport');
const BearerStrategy = require('passport-azure-ad').BearerStrategy

Endpoint in index.js:

app.use("/andon", passport.authenticate('oauth-bearer', { session: false }), andon);

Configuration from the documentation files:

    let options = {
  identityMetadata: appconfig.get("creds.identityMetadata"),
  clientID: appconfig.get("creds.clientID"),
  passReqToCallback: appconfig.get("creds.passReqToCallback")
}

let bearerStrategy = new BearerStrategy(options,
  function(token, done) {
    log.info('verifying the user');
    log.info(token, 'was the token retreived');
    findById(token.oid, function(err, user) {
      if (err) {
        return done(err);
      }
      if (!user) {
        // "Auto-registration"
        log.info('User was added automatically as they were new. Their oid is: ', token.oid);
        users.push(token);
        owner = token.oid;
        return done(null, token);
      }
      owner = token.oid;
      return done(null, user, token);
    });
  }
);
SebastianG
  • 8,563
  • 8
  • 47
  • 111

2 Answers2

4

You might be missing the following configuration step:

var passport = require('passport')
app.use(passport.initialize());
var BearerStrategy = require('passport-azure-ad').BearerStrategy
var bearerStrategy = new BearerStrategy (...)
passport.use(bearerStrategy);
Cody G
  • 8,368
  • 2
  • 35
  • 50
  • Found a few sample projects on the github repo -- managed to figure out which parts I was missing/forgetting about! This was pretty close! If you want to just add the initalize part to your answer I'll mark it as the answer so people that search in the future can find it. I don't want to mark my own answer as the solution. – SebastianG Aug 28 '18 at 15:50
  • I updated my answer :) --- It's actually okay to answer your own question, despite some people negatively overreacting to it. Ha, one of my most viewed questions/answers is that. https://stackoverflow.com/questions/44681065/how-do-i-specify-pdf-output-path-in-chrome-headless-mode/44681066#44681066 --- but another time I got like -10 votes so YMMV – Cody G Aug 28 '18 at 15:54
0

Was missing these two:

app.use(passport.initialize());
passport.use(bearerStrategy)

Added them in the right place and all works fine now.

SebastianG
  • 8,563
  • 8
  • 47
  • 111