如何在ember.js中生成oauth_signature和oauth_nonce?
如何在Ember.js中传递授权标题?
App.TwitterController = Ember.ObjectController.extend({
actions: {
URL : ' https://api.twitter.com/oauth/request_token',
parameters : {
oauth_consumer_key : '',
oauth_nonce : 'kllo9940pd9333jh',
oauth_timestamp : '1191242096',
oauth_signature_method : 'HMAC-SHA1',
oauth_version : '1.0',
},
consumerSecret : '',
encodedSignature : oauthSignature.generate('POST', URL, parameters, consumerSecret, tokenSecret),
loginTwitter: function() {
console.log('Event Clicked');
return new Ember.RSVP.Promise(function(resolve, reject) {
Ember.$.ajax({
url: 'https://api.twitter.com/oauth/request_token',
type: 'POST',
headers: {
"Authorization": 'OAuth oauth_callback="http%3A%2F%2example.com%3A3005%2Ftwitter%2Fcallback", oauth_consumer_key="", oauth_nonce="kllo9940pd9333jh", oauth_signature=' + encodedSignature + ', oauth_signature_method="HMAC-SHA1", oauth_timestamp="1191242096", oauth_version="1.0"'
},
contentType: 'application/x-www-form-urlencoded'
}).then(function(response) {
console.log('Successed');
console.log(response);
resolve (response);
}, function(xhr, status, error) {
console.log(error);
console.log('In Error');
reject(error);
});
});
},
}
});
错误无法验证oauth签名和令牌
我是Ember.js的新手。在上面的例子中,我使用了标题,这是否正确。如果没有,那么请告诉我如何在ember.js中使用授权标题
如何在ember.js中创建oauth_signature和oauth_nonce。任何图书馆?
它给出错误'参考:参数未定义'。 然后当我评论参数代码并从功能中删除。然后它会给出错误'参考:consumerSecret未定义'。
我不想让消费者保密。因为在twitter文档中,我只读取了回调网址,oauth_signaturem oauth_nonce,consumer_key和版本来请求令牌。
它不返回auth_token,oauth_secert。 我想在request_token url命中时访问auth_token等。
App.ApplicationController = Ember.Controller.extend({
URL : ' https://api.twitter.com/oauth/request_token',
parameters : {
oauth_consumer_key : '',
oauth_nonce : 'kllo9940pd9333jh',
oauth_timestamp : '1191242096',
oauth_signature_method : 'HMAC-SHA1',
oauth_version : '1.0',
},
consumerSecret : '',
// generates a RFC3986 encoded, BASE64 encoded HMAC-SHA1 hash
encodedSignature : oauthSignature.generate('POST', URL, parameters, consumerSecret, tokenSecret),
});
我还在ApplicationController中创建属性并在twitterController中访问,但同样的错误发生。
这一行也给出了错误oauthSignature.generate methid返回签名但它给出了错误。 encodedSignature = oauthSignature.generate(' POST',URL,参数,consumerSecret,tokenSecret), });
当我改为 encodedSignature:oauthSignature.generate(' POST',URL,参数,consumerSecret,tokenSecret), });
错误