Skip to content

Koa Server: Unable to verify authorization request state #58

@vshtishi

Description

@vshtishi

My callback request always fails with the same error. I am using koa, could it be related to the session configurations? Please tell me if I need to provide extra details, I have tried everything I found relevant with no success.

`router.get("/auth/twitter", (ctx, next) => {
return passport.authenticate(provider, {
scope: ['tweet.read', 'users.read', 'offline.access'],
})(ctx, next);
});

router.get("/auth/twitter/callback", async (ctx, next) => {
await passport.authenticate(provider, function (err, user, info) {
if (err) {
console.log(JSON.stringify(err, null, 2));
ctx.status = 500;
ctx.body = { error: "Internal Server Error" };
return;
}

if (!user) {
ctx.status = 401;
ctx.body = { error: "Authentication failed" };
return;
}

ctx.body = {
access_token: user.accessToken,
refresh_token: user.refreshToken,
profile: user.profile,
};
ctx.status = 200;
})(ctx, next);
});`

Koa server session config:

app.use(passport.initialize()); app.use(session({}, app)); app.use(passport.session());

Also the endpoints above are called from the frontend

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