2016-06-30 10 views
3

いつか私はexpressでauth0を使用しています。しかし、今私は1つの質問があります。 これは私のコードがどのように見えるかです:Passport-auth0アクセスアクセストークン

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にアクセスすることができます。私は本当に方法がわからないが、私はすでにいくつかのことを試みた。

ニルス

答えて

3

私はそれを得ました!今

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にアクセスすることができます。