正如标题所说,我在为我的环回应用程序集成第三方auth时遇到了问题。我已经按照文档中的所有步骤进行了操作,但似乎缺少某些内容?
我正在使用loopback-component-passport。正常的登录过程非常有效。
我遇到的问题是,当我将$ state(route)设置为authenticate:true时,它不会识别会话,cookie或$ rootScope.currentUser未被设置。
这是我假设导致重定向的代码(因为没有设置$ rootScope.currentUser)。
.run(['$rootScope', '$state', function($rootScope, $state) {
$rootScope.$on('$stateChangeStart', function(event, next) {
// redirect to login page if not logged in
if (next.authenticate && !$rootScope.currentUser) {
event.preventDefault(); //prevent current page from loading
$state.go('login');
}
});
}]);
loopback-component-passport不能开箱即用吗?有什么我需要做的,我没有看到? 我已将正确的代码添加到我的server.js文件中。
// to support JSON-encoded bodies
app.middleware('parse', bodyParser.json());
// to support URL-encoded bodies
app.middleware('parse', bodyParser.urlencoded({
extended: true
}));
// The access token is only available after boot
app.middleware('auth', loopback.token({
model: app.models.accessToken
}));
app.middleware('session:before', loopback.cookieParser('cookieSecret'));
app.middleware('session', loopback.session({
secret: 'mysecretkey',
saveUninitialized: true,
resave: true
}));
这是我的几条路线..
.state('account', {
abstract: true,
url: '/account',
templateUrl: 'views/account/account.html',
controller: 'AccountCtrl',
resolve: {
// Constant title
$title: function() { return 'Account Dashboard'; }
},
authenticate: true
})
.state('account.dashboard', {
url: '/dashboard',
templateUrl: 'views/account/streamers/dashboard.html',
controller: 'AccountDashboardCtrl',
resolve: {
// Constant title
$title: function() { return 'Account: Main Dashboard'; }
},
authenticate: true
})
这是我的providers.json(包括session和setAccessToken)
{
"twitch-login": {
"provider": "twitch",
"module": "passport-twitch",
"clientID": "myclientid",
"clientSecret": "myclientsecret",
"callbackURL": "/auth/twitch/callback",
"authPath": "/auth/twitch",
"callbackPath": "/auth/twitch/callback",
"successRedirect": "/#/account/dashboard",
"failureRedirect": "/login",
"scope": ["user_read"],
"session": true,
"setAccessToken": true,
"failureFlash": true
}
}