Skip to content

Commit

Permalink
fix(authentication-oauth): Make oAuth authentication work with cookie…
Browse files Browse the repository at this point in the history
…-session (#2614)
  • Loading branch information
cciocov authored Apr 29, 2022
1 parent 2dac771 commit 9f10bfc
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions packages/authentication-oauth/src/express.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,18 @@ export default (options: OauthSetupSettings) => {
req.session.redirect = redirect as string;
req.session.query = query;
req.session.headers = req.headers;
req.session.save((err: any) => {
if (err) {
next(`Error storing session: ${err}`);
} else {
next();
}
});
if (typeof(req.session.save) === 'function') {
req.session.save((err: any) => {
if (err) {
next(`Error storing session: ${err}`);
} else {
next();
}
});
}
else {
next();
}
});

authApp.get('/:name/authenticate', async (req: Request, res: Response, next: NextFunction) => {
Expand Down Expand Up @@ -107,12 +112,13 @@ export default (options: OauthSetupSettings) => {
};

await new Promise<void>((resolve, reject) => {
if (!req.session.destroy) {
if (req.session.destroy) {
req.session.destroy((err: any) => err ? reject(err) : resolve());
}
else {
req.session = null;
resolve();
}

req.session.destroy((err: any) => err ? reject(err) : resolve());
});

debug(`Calling ${authService}.create authentication with strategy ${name}`);
Expand Down

0 comments on commit 9f10bfc

Please sign in to comment.