2016-06-30 10 views
3

Seit irgendwann benutze ich auth0 mit Express. Aber jetzt habe ich eine Frage. Dies ist, wie mein Code wie folgt aussieht:Pass-auth0 access accessToken

var passport = require('passport'); 
 
var Auth0Strategy = require('passport-auth0'); 
 

 
var strategy = new Auth0Strategy({ 
 
    domain: '', 
 
    clientID: '', 
 
    clientSecret: '', 
 
    callbackURL: '/loginapi/callback' 
 
}, function (accessToken, refreshToken, extraParams, profile, done) { 
 
    // accessToken is the token to call Auth0 API (not needed in the most cases) 
 
    // extraParams.id_token has the JSON Web Token 
 
    // profile has all the information from the user 
 
    return done(null, profile); 
 
}); 
 

 
passport.use(strategy); 
 

 
// This is not a best practice, but we want to keep things simple for now 
 
passport.serializeUser(function (user, done) { 
 
    done(null, user); 
 
}); 
 

 
passport.deserializeUser(function (user, done) { 
 
    done(null, user); 
 
}); 
 

 
module.exports = strategy;

Aber wie kann ich das accessToken in einem ausdrücklichen Wunsch wie ein Bedienelement zugreifen. Ich weiß wirklich nicht wie, aber ich habe schon einige Sachen ausprobiert.

Nils

Antwort

3

Ich habe es Jungs!

var strategy = new Auth0Strategy({ 
 
    domain: '', 
 
    clientID: '', 
 
    clientSecret: '', 
 
    callbackURL: '/loginapi/callback' 
 
}, function (accessToken, refreshToken, extraParams, profile, done) { 
 
    // accessToken is the token to call Auth0 API (not needed in the most cases) 
 
    // extraParams.id_token has the JSON Web Token 
 
    // profile has all the information from the user 
 
    var info = { 
 
     "profile": profile, 
 
     "accessToken": accessToken, 
 
     "refreshToken": refreshToken, 
 
     "extraParams": extraParams 
 
    }; 
 
    return done(null, info); 
 
});

Jetzt kann ich die accessToken Zugriff einfach mit dem req.user Objekt.