【发布时间】:2019-06-25 19:35:14
【问题描述】:
我正在试验 Spotify API,我正在使用 Node JS、Express、React、Passport JS。我使用护照 JS 进行身份验证,在设置中,有一个参数是访问令牌。使用此访问令牌,我可以访问用户的库和其他信息。但我不确定之后如何访问此访问令牌。我的意思是,我想在用户单击某个按钮时使用它,而不是在用户登录时使用它。如何“保存”此访问令牌或稍后访问它?
我尝试在“done(err,user)”之后返回访问令牌,但我不知道它被返回到哪里。
这是我的护照设置:
passport.use(
new SpotifyStrategy(
{
clientID: keys.spotify.clientID,
clientSecret: keys.spotify.clientSecret,
callbackURL: "/callback"
},
function(accessToken, refreshToken, expires_in, profile, done) {
User.findOrCreate({
where: {
user_spotify_id: profile.id,
username: profile.username,
email: profile._json.email,
country: profile.country,
birthdate: profile._json.birthdate
}
}).then(([user, created]) => {
done(null, user);
// return accessToken;
});
}
)
);
【问题讨论】:
标签: reactjs express passport.js