Skip to content

Error: State is not matching #8

Open
@nodesocket

Description

@nodesocket

Seeing intermittent errors calling OAuth.auth(), where it falls into the fail() block. The err is simply:

[Error: State is not matching]

What does that mean? We are using redis to store sessions by the way.

Here is the full block of code we are using:

////
// OAuth signin route
////
app.post('/oauth/signin', [
    oauthLogger,
    jsonParser,
    function(req, res) {
        if(!req.body) {
            res.status(400).send({
                error: {
                    status_code: 400,
                    status: 'Bad Request',
                    message: 'Missing required body'
                }
            }).end();

            return;
        }

        if(!req.body.provider || !req.body.code) {
            res.status(400).send({
                error: {
                    status_code: 400,
                    status: 'Bad Request',
                    message: 'Missing required parameter'
                }
            }).end();

            return;
        }

        OAuth.auth(req.body.provider, req.session, {
            code: req.body.code
        })
        .then(function(requestObject) {
            return requestObject.me();
        })
        .then(function(me) {
            if(!me.raw.id) {
                res.status(500).send({
                    error: {
                        status_code: 500,
                        status: 'Internal Server Error',
                        message: 'Missing required id'
                    }
                }).end();

                return;
            }

            req.session.oauth.provider = req.body.provider;
            req.session.oauth.id = me.raw.id;

            res.status(200).send({
                email: me.email,
                avatar: me.avatar
            }).end();
        })
        .fail(function(err) {
            res.status(503).send({
                error: {
                    status_code: 503,
                    status: 'Service Unavailable',
                    message: err.toString()
                }
            }).end();
        });
    }
]);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions