【发布时间】:2018-06-05 21:33:28
【问题描述】:
我有自定义 OAuth 提供程序 (koa2-oauth-server) 在端口 8080 上运行。
我有一个客户端应用程序,它使用Passport 来验证使用OAuth2Strategy 的请求。
以下代码为 OAuth 配置护照
passport.use(
new OAuth2Strategy({
tokenURL: 'http://localhost:8080/oauth/token',
authorizationURL: 'http://localhost:8080/oauth/authorize',
clientID: 'xxx',
clientSecret: 'xxx',
callbackURL: 'http://localhost:3000/oauth/redirect'
}, (accessToken, refreshToken, profile, done) => {
console.log(profile); // This is always empty object
done(null, profile);
})
);
以下代码生成访问令牌
router.post('/oauth/token', oauth.token(),
(ctx,next) => {
// TODO: Profile information not being sent
const userid = ctx.state.oauth.token.user.id;
ctx.body = db.users.find(function(aUser){
return aUser.id == userid;
})
}
);
我想在护照回调函数中接收个人资料信息。 我尝试发送第二个代码块中的用户个人资料信息,但没有成功。
我尝试阅读koa2-oauth-server 和node-oauth2-server 的代码以弄清楚如何发送个人资料信息,但没有成功。
我应该如何配置 OAuth 提供程序以将配置文件信息发送回客户端?
【问题讨论】:
标签: node.js oauth passport.js koa2