I am having trouble to get oauth working on angular. when I enter the link directly to the browser
http://localhost:8080/auth/twiter
I am able to connect using oauth and get a respond However when I try to do that in angular with the following code
login_twitter : function login_twitter(){
var deferred = $q.defer();
$http.get('auth/twitter')
.success(function (data,status){
if(status === 200 && data.state=='success'){
user = data.user.name;
defered.resolve();
}
else{
deferred.reject();
}
})
.error(function (data){
deferred.reject();
});
return deferred.promise;
I am getting an error from the browser
XMLHttpRequest cannot load ....link... No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access.
In my server I tried with (res.header and res.setHeader)
app.use(function (req, res, next) {
res.setHeader('Access-Control-Allow-Origin', 'http://localhost:8080');
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');
res.setHeader('Access-Control-Allow-Credentials', true);
next();
});
Can any one please help me out? I've been stuck for a while. Or is there any examples that can use Oauth to login with angular and node , because most of tutorials are with node and ejs/jade