最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

如何配置OAuth服务器以发送配置文件信息?

IT培训 admin 5浏览 0评论

如何配置OAuth服务器以发送配置文件信息?

我在端口8080上运行自定义OAuth提供程序(koa2-oauth-server)。

我有一个客户端应用程序,它使用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-servernode-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文件中的函数以符合我的要求。

如何配置OAuth服务器以发送配置文件信息?

我在端口8080上运行自定义OAuth提供程序(koa2-oauth-server)。

我有一个客户端应用程序,它使用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-servernode-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文件中的函数以符合我的要求。

发布评论

评论列表 (0)

  1. 暂无评论