Answer the question
In order to leave comments, you need to log in
Authorization through vk.api and access control to certain pages of the site?
Good afternoon. Since I'm not familiar with server technologies, I don't know where to dig yet.
Situation: the site has authorization through Vkontakte. After the user is authorized - some kind of cookie is set? Or what else? (VK authorization works through Open Auth)
I need to somehow identify the user (I can easily get his vk id) and give him the right to view certain pages. Another user may have a different set of pages.
I'm using node.js + express
What is the process for such access control? Should I write something to the mongo database? Do a "session"?) As you can see, my question is just like from a teapot, and I can't specifically formulate it, because I don't know how the process of authorization and user authentication looks like. What do you recommend to read a small volume?
Thank you.
Answer the question
In order to leave comments, you need to log in
To work with OAuth at the moment, fertilizer of all use the passport.js module . As for access control. Instead of abbreviated
app.get('/route', function(req, res) {
// ...
});
app.get('/route', [loadUser1, loadUser2, ..., loadUserN], function(req, res) {
// ...
});
function loadUser(req, res, next) {
if (req.session.user_id) {
next();
}
else {
res.redirect('/sessions/new');
}
}
VK.Auth.getLoginStatus(function(response) {
if (response.session) {
/* Сверяем данные сессии от вконтакта с доступами для этого пользователя в базе. Если нет записи для этого пользователя, то создаем ее. */
} else {
/* Пшел вон */
}
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question