我的應用程序運行在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