I just finished auth0 angularjs tutorial described at https://auth0.com/docs/quickstart/spa/angular/no-api with a successfull twitter login (so i got token). I want to extend the seed project doing some requests to twitter API to get the user timeline, etc.
I've tried it doing $http
request with jsonp and adding a request interceptor at app.js with the Authorization header. It looks like this:
HomeCtrl
$http.jsonp('https://api.twitter.com/1.1/statuses/home_timeline.json?callback=JSON_CALLBACK')
.then(function(data) {
console.log(data);
});
App.js
.config( function myAppConfig ($routeProvider, authProvider, $httpProvider, $locationProvider, jwtInterceptorProvider, RestangularProvider) {
...
$httpProvider.interceptors.push('jwtInterceptor');
})
.factory('jwtInterceptor', function(store) {
return {
request: function(config) {
config.headers = config.headers || {};
config.headers.Authorization = 'Bearer ' + store.get('token');
console.log(config);
return config;
}
};
})
Response returns 401 Authorization Required:
Failed to load resource: the server responded with a status of 401 (Authorization Required)
https://api.twitter.com/1.1/statuses/home_timeline.json?callback=angular.callbacks._0
What am i doing wrong? Should I make another thing before do request to get timeline? Maybe am i confused about oauth works and i need access_token to do the request?
Thanks in advance.