【发布时间】:2017-06-14 14:27:41
【问题描述】:
我尝试在我的 MEAN 应用程序中使用 Amazon Passport 进行身份验证,但遇到了跨源错误。我的应用程序是这样设置的:
查看:
<a id="LoginWithAmazon" ng-click="vm.auth()">
<img class="responsive-img amazon-button"/>
</a>
控制器:
vm.auth = function () {
Auth.login()
.then(function () {
$location.path('/');
})
.catch(function (err) {
vm.error = err;
});
}
服务:
vm.login = function () {
var deferred = $q.defer();
$http.post('/auth/amazon')
.then(function (res) {
console.log('SUCCESS! ', res);
deferred.resolve();
})
.catch(function (err) {
console.log('ERR: ', err);
deferred.reject(err.data);
});
return deferred.promise;
};
在我的 Express/NodeJS 上下文中...
护照是这样配置的:
passport.use(new AmazonStrategy({
clientID: config.amazon.clientID,
clientSecret: config.amazon.clientSecret,
callbackURL: "http://localhost:9000/test"
},
function(accessToken, refreshToken, profile, done) {
console.log('SUCCESS AUTH: ', profile);
process.nextTick(function() {
return done(null,profile);
});
});
}
));
快车路线:
router.post('/auth/amazon', function (req, res, next) {
passport.authenticate('amazon', function (err, user, info) {
console.log('Err? ', err);
console.log('User: ', user);
})(req, res, next);
});
我尝试过使用<a href="{{amazonUrl}} target="_blank">Login with Amazon</a>,但也无济于事。我已在使用 Amazon 的配置登录时将 http://localhost:9000 列入白名单。任何帮助将不胜感激。
【问题讨论】:
标签: angularjs node.js express passport.js mean-stack