Configure Satellizer.js for Vkontakte oauth

516 Views Asked by At

I'm trying to configure satellizer for vk.com authorization. However, I keep getting 500 internal server error when trying to authenticate. Here is my configuration:

On clientside:

$authProvider.oauth2({
    name: 'vkontakte',
    url: '/auth/vk',
    redirectUri:window.location.origin || window.location.protocol + '//' + window.location.host,
    clientId: 'my-client-id',
    authorizationEndpoint: 'http://oauth.vk.com/authorize',
    scope: 'friends, photos, email, photo_big',
    display: 'popup',
    responseType: 'code',
    requiredUrlParams: ['response_type', 'client_id', 'redirect_uri', 'display', 'scope', 'v'],
    scopeDelimiter: ',',
    v: '5.37'
});

And relevant part of server-side routing:

//vkontakte
app.post('/auth/vk', function(req, res) {
    var accessTokenUrl = 'https://oauth.vk.com/access_token';
    var params = {
        code: req.body.code,
        client_id: req.body.clientId,
        client_secret: config.auth.facebook.clientSecret,
        redirect_uri: req.body.redirectUri
    };

    request.get({ url: accessTokenUrl, qs: params, json: true }, function(err, response, accessToken) {
        if (response.statusCode !== 200) {
            return res.status(500).send({ message: accessToken.error.message });
        }
        var graphApiUrl = 'https://api.vk.com/method/users.get?user_id=' + accessToken.user_id +'&access_token=' + accessToken;

        request.get({ url: graphApiUrl, qs: accessToken, json: true }, function(err, response, profile) {
           ...
        });
    });
});

Looks like I'm doing something wrong. Facebook authorization works fine so the problem is most likely with configuration. Does anyone have any ideas?

0

There are 0 best solutions below