我的应用程序运行在NodeJS,ExpressJS和AngularJS上。我正在尝试使用PassportJS进行Facebook身份验证。为了避免发布大量不必要的代码,我们只需说Passport代码按预期工作并登录Facebook,抓取令牌并接收响应。ExpressJS和Angular - '离开'应用程序做服务器端身份验证
在我的路线设置为ExpressJS如下:
app.get('/', routes.index);
app.get('/fbauth', passport.authenticate('facebook', { scope: 'email' }));
app.get('/fbauthed', passport.authenticate('facebook',{ failureRedirect: '/' }), routes.loggedin);
app.get('/logout', function(req, res) {
req.logOut();
res.redirect('/');
});
我的服务器设置在localhost:3000
。
问题
我的问题是,角是不是跟这个行为的。当我在我的页面上添加一个链接到href="/fbauth"
(这是localhost:3000/fbauth
)我看到地址栏变为localhost:3000/fbauth
秒,然后我的主页localhost:3000
页面重新加载。
但是,如果我在地址栏中输入localhost:3000/fbauth
,身份验证就会发生,我会转到facebook - >localhost:3000/fbauthed
。
我认为发生这种情况,因为角路由试图“接管”在<a>
链接的网址,但我不知道如何去实现它。我试过配置我的角路由:
when('/fbauth', {
redirectTo: '/fbauth'
}).
但是,这加载一个空白屏幕。我怎样才能使这两个工作在一起?
看看'$ location'服务文档中的'HTML链接重写'部分http://docs.angularjs.org/guide/dev_guide.services.$location。它有关于如何阻止Angular重写网址的详细信息 – Chandermani