Skip to content

Commit

Permalink
fix: Only initialize default Express session if oAuth is actually used (
Browse files Browse the repository at this point in the history
  • Loading branch information
daffl authored Oct 26, 2019
1 parent 6530b4d commit 9b9b43f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 7 additions & 1 deletion packages/authentication-oauth/src/express.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @ts-ignore
import { express as grantExpress } from 'grant';
import Debug from 'debug';
import session from 'express-session';
import { Application } from '@feathersjs/feathers';
import { AuthenticationResult } from '@feathersjs/authentication';
import qs from 'querystring';
Expand All @@ -26,10 +27,15 @@ export default (options: OauthSetupSettings) => {
}

const { path } = config.defaults;
const expressSession = options.expressSession || session({
secret: Math.random().toString(36).substring(7),
saveUninitialized: true,
resave: true
});
const grantApp = grant(config);
const authApp = express();

authApp.use(options.expressSession);
authApp.use(expressSession);

authApp.get('/:name', (req, res) => {
const { feathers_token, ...query } = req.query;
Expand Down
8 changes: 1 addition & 7 deletions packages/authentication-oauth/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
import { RequestHandler } from 'express';
import session from 'express-session';
import { Application } from '@feathersjs/feathers';

export interface OauthSetupSettings {
authService?: string;
expressSession?: RequestHandler;
linkStrategy: string;
expressSession: RequestHandler;
}

export const getDefaultSettings = (_app: Application, other?: Partial<OauthSetupSettings>) => {
const defaults: OauthSetupSettings = {
linkStrategy: 'jwt',
expressSession: session({
secret: Math.random().toString(36).substring(7),
saveUninitialized: true,
resave: true
}),
...other
};

Expand Down

0 comments on commit 9b9b43f

Please sign in to comment.