Node.js 如何配置OAuth服务器以发送配置文件信息?
我在端口8080上运行了自定义OAuth提供程序(Node.js 如何配置OAuth服务器以发送配置文件信息?,node.js,oauth,passport.js,koa2,Node.js,Oauth,Passport.js,Koa2,我在端口8080上运行了自定义OAuth提供程序(koa2 OAuth服务器) 我有一个客户端应用程序,它使用Passport使用OAuth2Strategy对请求进行身份验证 以下代码为OAuth配置passport passport.use( new OAuth2Strategy({ tokenURL: 'http://localhost:8080/oauth/token', authorizationURL: 'http://localhost:80
koa2 OAuth服务器
)
我有一个客户端应用程序,它使用Passport
使用OAuth2Strategy
对请求进行身份验证
以下代码为OAuth配置passport
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;
})
}
);
我想在passport回调函数中接收配置文件信息。
我尝试发送用户配置文件信息,如第二段代码所示,但没有成功
我试图阅读koa2oauth服务器
和node-oauth2-server
的代码,以了解如何发送配置文件信息,但没有成功
我应该如何配置OAuth提供程序以将配置文件信息发送回客户端?我检查了passport-oauth2的源代码,结果发现该函数是罪魁祸首
/**
* Retrieve user profile from service provider.
*
* OAuth 2.0-based authentication strategies can overrride this function in
* order to load the user's profile from the service provider. This assists
* applications (and users of those applications) in the initial registration
* process by automatically submitting required information.
*
* @param {String} accessToken
* @param {Function} done
* @api protected
*/
OAuth2Strategy.prototype.userProfile = function(accessToken, done) {
return done(null, {});
};
我重载了js文件中的函数以满足我的需求