Facebook 使用 Parse 客户端站点登录,使用带有 Express js 的用户对象
Facebook login with Parse client site, use user object with Express js
我正在尝试使用 Parse 和 Facebook Javascript SDK 创建登录过程。身份验证在客户端没有问题,但我也需要在服务器端访问用户对象(由 Parse SDK 创建)。我怎样才能以最优雅的方式做到这一点?我想当我通过 Parse 登录 Facebook 时设置了一个 cookie,所以我可以从服务器访问用户对象。或者我应该做登录过程服务器端?有什么建议吗?
我遇到了同样的问题。事实证明,您可以使用服务器端身份验证或客户端身份验证。您不能将两者混合搭配。看看他们的 official blog post about sessions。
var parseExpressCookieSession = require('parse-express-cookie-session');
// In your middleware setup...
app.use(express.cookieParser('YOUR_SIGNING_SECRET'));
app.use(parseExpressCookieSession({ cookie: { maxAge: 3600000 } }));
// Making a "login" endpoint is SOOOOOOOO easy.
app.post("/login", function(req, res) {
Parse.User.logIn(req.body.username, req.body.password).then(function() {
// Login succeeded, redirect to homepage.
// parseExpressCookieSession will automatically set cookie.
res.redirect('/');
},
function(error) {
// Login failed, redirect back to login form.
res.redirect("/login");
});
});
此外,我在浏览文档时遇到了这个问题:
You can add Parse.User authentication and session management to your
Express app using the parseExpressCookieSession middleware. You just
need to call Parse.User.logIn() in Cloud Code, and this middleware
will automatically manage the user session for you.
You can use a web form to ask for the user's login credentials, and
log in the user in Cloud Code when you receive data from this form.
After you call Parse.User.logIn(), this middleware will automatically
set a cookie in the user's browser. During subsequent HTTP requests
from the same browser, this middleware will use this cookie to
automatically set the current user in Cloud Code.
...
When you work with user data, you should use HTTPS whenever possible.
To protect your app and your users, the parseExpressCookieSession
middleware requires you to use HTTPS. For your convenience, we also
provide a parseExpressHttpsRedirect middleware for redirecting all
HTTP requests to HTTPS.
我正在尝试使用 Parse 和 Facebook Javascript SDK 创建登录过程。身份验证在客户端没有问题,但我也需要在服务器端访问用户对象(由 Parse SDK 创建)。我怎样才能以最优雅的方式做到这一点?我想当我通过 Parse 登录 Facebook 时设置了一个 cookie,所以我可以从服务器访问用户对象。或者我应该做登录过程服务器端?有什么建议吗?
我遇到了同样的问题。事实证明,您可以使用服务器端身份验证或客户端身份验证。您不能将两者混合搭配。看看他们的 official blog post about sessions。
var parseExpressCookieSession = require('parse-express-cookie-session');
// In your middleware setup...
app.use(express.cookieParser('YOUR_SIGNING_SECRET'));
app.use(parseExpressCookieSession({ cookie: { maxAge: 3600000 } }));
// Making a "login" endpoint is SOOOOOOOO easy.
app.post("/login", function(req, res) {
Parse.User.logIn(req.body.username, req.body.password).then(function() {
// Login succeeded, redirect to homepage.
// parseExpressCookieSession will automatically set cookie.
res.redirect('/');
},
function(error) {
// Login failed, redirect back to login form.
res.redirect("/login");
});
});
此外,我在浏览文档时遇到了这个问题:
You can add Parse.User authentication and session management to your Express app using the parseExpressCookieSession middleware. You just need to call Parse.User.logIn() in Cloud Code, and this middleware will automatically manage the user session for you.
You can use a web form to ask for the user's login credentials, and log in the user in Cloud Code when you receive data from this form. After you call Parse.User.logIn(), this middleware will automatically set a cookie in the user's browser. During subsequent HTTP requests from the same browser, this middleware will use this cookie to automatically set the current user in Cloud Code.
...When you work with user data, you should use HTTPS whenever possible. To protect your app and your users, the parseExpressCookieSession middleware requires you to use HTTPS. For your convenience, we also provide a parseExpressHttpsRedirect middleware for redirecting all HTTP requests to HTTPS.