angularjs - Passport google authentication with javascript fullstack -
i'm trying add google authentication passport in application, has been generated using yeoman fullstack-generator.
inside login controller have request:
$scope.googleauth = function(){ $http.get('/auth/google'); };
but when call function have error:
xmlhttprequest cannot load https://accounts.google.com/o/oauth2/auth?response_type=code&redirect_uri=h…d=<my-client-id-here>. no 'access-control-allow-origin' header present on requested resource. origin 'http://localhost:9000' therefore not allowed access.
i tried fix problem adding middleware layer in express.js file:
app.use(function (req, res, next) { // website wish allow connect res.setheader('access-control-allow-origin', 'http://localhost:9000'); // request methods wish allow res.setheader('access-control-allow-methods', 'get, post, options, put, patch, delete'); // request headers wish allow res.setheader('access-control-allow-headers', 'x-requested-with,content-type'); // set true if need website include cookies in requests sent // api (e.g. in case use sessions) res.setheader('access-control-allow-credentials', true); // pass next layer of middleware next(); });
but still not working. right solution? , safe?
i fixed problem using hyperlink instead of button following
<a target="_self" href="/auth/google" class="btn btn-danger">google+</a>
i used target="_self"
otherwise angular redirects home page because, think, considers /auth/google
route of app.
Comments
Post a Comment