【问题标题】:MEAN Stack Amazon Passport AuthMEAN Stack Amazon Passport 身份验证
【发布时间】: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);
});

当我尝试发出身份验证请求时,我收到以下错误:

我尝试过使用&lt;a href="{{amazonUrl}} target="_blank"&gt;Login with Amazon&lt;/a&gt;,但也无济于事。我已在使用 Amazon 的配置登录时将 http://localhost:9000 列入白名单。任何帮助将不胜感激。

【问题讨论】:

    标签: angularjs node.js express passport.js mean-stack


    【解决方案1】:

    看起来您向应该重定向 (302) 的端点发出 AJAX 请求。端点可能包含一个登录页面,用户应该能够看到并使用它。

    确保您遵循 oauth 规范,并且不会过早发出 AJAX 请求。该协议要求您首先重定向到他们的登录页面,然后,只有当您拥有一次性代码时,您才发出 AJAX 请求以将代码交换为访问令牌。

    【讨论】:

      猜你喜欢
      • 2021-12-04
      • 2019-03-28
      • 2015-03-16
      • 2014-11-15
      • 2017-05-13
      • 2016-01-02
      • 2016-09-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多