-
-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: authentication strategy cookies and split cookies per domain
- Loading branch information
Showing
10 changed files
with
76 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 35 additions & 2 deletions
37
packages/medusa-plugin-auth/src/auth-strategies/jwt-override.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,53 @@ | ||
import passport from 'passport'; | ||
import { Strategy as JWTStrategy } from 'passport-jwt'; | ||
import { ConfigModule } from '@medusajs/medusa/dist/types/global'; | ||
import { AUTH_TOKEN_COOKIE_NAME } from '../types'; | ||
import { ADMIN_AUTH_TOKEN_COOKIE_NAME, STORE_AUTH_TOKEN_COOKIE_NAME } from "../types"; | ||
|
||
export function loadJwtOverrideStrategy(configModule: ConfigModule): void { | ||
const { jwt_secret } = configModule.projectConfig; | ||
passport.use( | ||
'jwt', | ||
new JWTStrategy( | ||
{ | ||
jwtFromRequest: (req) => req.cookies[AUTH_TOKEN_COOKIE_NAME] ?? req.session.jwt, | ||
jwtFromRequest: (req) => { | ||
return req.cookies[STORE_AUTH_TOKEN_COOKIE_NAME] ?? req.cookies[ADMIN_AUTH_TOKEN_COOKIE_NAME] ?? req.session.jwt | ||
}, | ||
secretOrKey: jwt_secret, | ||
}, | ||
async (jwtPayload, done) => { | ||
return done(null, jwtPayload); | ||
} | ||
) | ||
); | ||
|
||
// The bellow code will be available for the next version of medusa core | ||
/*passport.use( | ||
'admin-jwt', | ||
new JWTStrategy( | ||
{ | ||
jwtFromRequest: (req) => { | ||
return req.cookies[ADMIN_AUTH_TOKEN_COOKIE_NAME] ?? req.session.jwt | ||
}, | ||
secretOrKey: jwt_secret, | ||
}, | ||
async (jwtPayload, done) => { | ||
return done(null, jwtPayload); | ||
} | ||
) | ||
); | ||
passport.use( | ||
'store-jwt', | ||
new JWTStrategy( | ||
{ | ||
jwtFromRequest: (req) => { | ||
return req.cookies[STORE_AUTH_TOKEN_COOKIE_NAME] ?? req.session.jwt_store | ||
}, | ||
secretOrKey: jwt_secret, | ||
}, | ||
async (jwtPayload, done) => { | ||
return done(null, jwtPayload); | ||
} | ||
) | ||
);*/ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters