【发布时间】:2015-04-19 19:59:11
【问题描述】:
这是我的场景。 nodejs 中的服务器处理身份验证过程,而前端我们有 angularjs。当用户单击按钮时,他使用 Facebook 登录,然后服务器处理身份验证的所有方面,最后重定向到 angularjs 应用程序的 uri。我们在服务器中有类似的东西
module.exports = function(request, reply) {
if (request.auth.isAuthenticated) {
var profile = request.auth.credentials.profile.raw;
// set to cookie
request.auth.session.set(profile);
// Perform any account lookup or registration, setup local session,
// and redirect to the application. The third-party credentials are
// stored in request.auth.credentials. Any query parameters from
// the initial request are passed back via request.auth.credentials.query
// here we should redirect the app flow somewhere
return reply({ profile: profile.id }).redirect('http://localhost:8080/app');
}
return reply('Unauthorized').code(401);
};
我的问题是我不知道如何在 angularjs 中检索配置文件对象。我的意思是我知道存在 $http 提供程序,但在以下情况下,请求不是从 angularjs 开始的。如果用户签名成功,则服务器会使用 SPA 回复流程
$http.get('/app')
.success(function(data){
console.log(data);
});
【问题讨论】:
-
加载 SPA 后,您仍必须使用
$http获取配置文件数据。 -
好的,但是应该通过哪个 uri?
-
我的意思是我一直希望 $http 提供程序开始调用,但在这种情况下,流程是不同的。服务器为 SPA 服务
-
我应该使用 /app 吗?
-
在这两种情况下,SPA 都是从服务器提供的。所以流量不变。您必须重定向到应用程序 uri /app