【问题标题】:Passport-auth0 access accessTokenPassport-auth0 访问 accessToken
【发布时间】:2016-11-02 14:20:36
【问题描述】:

因为有时我将 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;

但是我怎样才能在像用户元素这样的快速请求中访问 accessToken。我真的不知道怎么做,但我已经尝试了一些东西。

尼尔斯

【问题讨论】:

    标签: express passport.js auth0


    【解决方案1】:

    我明白了!

    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);
    });

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

    【讨论】:

      猜你喜欢
      • 2021-05-30
      • 1970-01-01
      • 2017-12-01
      • 2016-08-28
      • 2017-12-29
      • 1970-01-01
      • 2020-01-19
      • 2019-07-20
      • 2021-12-04
      相关资源
      最近更新 更多