8000 fix: Only initialize default Express session if oAuth is actually used by daffl · Pull Request #1648 · feathersjs/feathers · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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