Passport-auth0访问accessToken

Noi*_*oim 5 express passport.js auth0

由于有时我将auth0与express一起使用。但是现在我有一个问题。这是我的代码的样子:

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;
Run Code Online (Sandbox Code Playgroud)

但是,如何在像用户元素这样的明确请求中访问accessToken。我真的不知道如何,但是我已经尝试了一些东西。

尼尔斯

Noi*_*oim 6

我知道了!

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);
});
Run Code Online (Sandbox Code Playgroud)

现在,我可以简单地使用req.user对象访问accessToken。