我想在 node.js 中使用 simple-oauth2 授权我的应用程序中的 gmail 登录,并尝试获取用户配置文件,最初我进行身份验证,代码是
var oauth2 = require('simple-oauth2')({
clientID: configAuth.googleAuth.clientID,
clientSecret: configAuth.googleAuth.clientSecret,
site: 'https://accounts.google.com/o/',
tokenPath: 'https://accounts.google.com/o/oauth2/token',
authorizationPath: 'oauth2/auth'
});
// 授权uri定义
var authorization_uri = oauth2.authCode.authorizeURL({
redirect_uri: 'http://localhost:8080/auth/google/callback',
scope: 'https://www.googleapis.com/auth/userinfo.profile',
scope: 'https://www.googleapis.com/auth/analytics.readonly',
scope: 'https://www.googleapis.com/auth/userinfo.email',
state: '382332$'
});
app.get('/auth/google', function (req, res) {
res.redirect(authorization_uri);
});
回调是,
app.get('/auth/google/callback', function (req, res) {
var code = req.query.code;
oauth2.authCode.getToken({
code: code,
redirect_uri: 'http://localhost:8080/auth/google/callback'
}, saveToken);
function saveToken(error, result, profile1) {
if (error) {
console.log('Access Token Error', error);
}
token = oauth2.accessToken.create(result);
console.log('token',token)
}
令牌的结果是这样的:
{ access_token: 'ya29.lQKN8a2ECM0h5ECWL4NcThS924m_eMUWg9I3BVfRvkTiK-lt- 8_1bCLjBmtmi68Kg8k',
token_type: 'Bearer',
expires_in: 3599,
id_token: 'somelongstring',
expires_at: Sat Feb 27 2016 16:38:05 GMT+0530 (India Standard Time)
}
在令牌响应中,我无法获得刷新令牌。还有其他方法可以获取刷新令牌吗?
以及登录成功后如何获取登录用户的个人资料详细信息。请提出一些解决方案..!提前致谢 !!