2015-03-03 99 views
3

我一直在使用passport.js。它的工作原理,我可以很容易地从API获取oauth_tokenVerifier通过oauth令牌访问用户配置文件passport.js

在passport.js每个API具有战略基本上决定如何使用该API服务器进行通信。在最后一个回调获取返回的用户配置文件。

但是我看到没有办法用oauth_token得到profile自己。它在Oauth认证结束时一次性地将数据保存在session或db中。

有什么办法,我可以用我的oauth_token直接访问用户配置文件的任何时间usingpassport方法。

在原型中,我看到userProfile功能,它做我所需要的,但它的某种私人方法。我不知道如何使用它

更新1

我一直在捡破烂passport.js的混帐回购协议,我才知道他们使用的“node-oauth”管理的API调用服务器。这在任何策略_oauth中都可用。

但我不知道调用什么调用来获取资源令牌。此外,我必须逐步启动所有API调用以模拟令牌访问调用。有没有任何标准的方法来做到这一点。

回答

1

没有挖掘到的代码(不过话说之前使用护照),我假设oauth_token被存储在数据库中的用户数据。您可能必须直接访问数据库模型才能获取令牌,然后可以将其与提供程序API一起使用,以访问所需的信息。

0

访问以下页面以掌握如何使用_oauth属性。

https://github.com/ciaranj/node-oauth

它的工作原理是这样的:

oauth.get(
    'https://api.twitter.com/1.1/trends/place.json?id=23424977', 
    'your user token for this app', //test user token 
    'your user secret for this app', //test user secret    
    function (e, data, res){ 
    if (e) console.error(e);   
    console.log(require('util').inspect(data)); 
    done();  
    }); 

如果你实现自己的OAuth1.0策略,您可以轻松地可能会覆盖 下面的方法来实现自己的逻辑,取出由配置文件数据远程服务器的OAuth:

/** 
* @overwritten 
* @method userProfile 
* @class OAuth1Strategy 
* @description used by OAuth1Strategy class while authenticating 
* to get the user profile from the server 
*/ 
OAuth1Strategy.prototype.userProfile = 
function(token, tokenSecret, params, done) { 

    this._oauth.get(
    config.profileUrl, 
    token, 
    tokenSecret,   
    function (e, data, res){ 
     if (e) console.error(e);   
     console.log(require('util').inspect(data)); 
     done(e, data);  
    }); 
};