【发布时间】:2016-07-05 17:27:11
【问题描述】:
在经历了OAuth2的多个步骤后,收到access_token后该怎么办?
app.get('/oauth2', function(req, res) {
var code = req.query.code;
var url = "https://.../oauth/access_token";
var options = {
url: url,
method: "POST",
form: {
client_id: '...',
client_secret: '...',
grant_type: 'authorization_code',
redirect_uri: 'http://localhost:8080/oauth2',
code: code,
},
json: true
}
request(options, function(err, response, body) {
// I need to save the user in database if she doesn't exist
// Then redirect, but should I pass the access_token to the redirect?
res.redirect('/'); // or res.redirect('/?access_token=zzz')
}
// Also, should the access_token be encrypted
// Does it need to be saved in database?
// Does it go in local storage?
});
我想要一些我在回复中收到的信息,因此需要将其存储在数据库中。但是我具体用 access_token 做什么呢?它是否保存到数据库中?应该加密吗?当我重定向时,是否将其添加为查询字符串?我是否将其存储在本地存储中?如果有,怎么做?
【问题讨论】: