-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(medusa): Separate JWT auth strategies per domain #2646
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
c449884
hotfix
pKorsholm 58e1221
remove unused import
pKorsholm 47cce03
add changeset
pKorsholm 06f58c9
fix: Use find instead of findOne in customer + user services
olivermrbl fe6e5ef
fixed tests
olivermrbl ab9e536
Fix customer query
olivermrbl 38a60bd
wip
olivermrbl b6d6938
fix(medusa): customer middleware
adrien2p 25d3250
wip
olivermrbl 54df3d1
Throw 401 on all store endpoint where customer id is required
olivermrbl c7bca61
Revert
olivermrbl 24317f7
fix: authenticateCustomer method
olivermrbl f77f0d6
fix: Add new customer auth middleware
olivermrbl a1d6646
revert user service
olivermrbl 35f1c39
fix: Rename require auth customer
olivermrbl 1faaec5
fix comment
olivermrbl e648cb1
set test request token correctly
pKorsholm b68f129
rename export
olivermrbl f9525ba
Merge branch 'fix/jwt-strategies' of github.com:medusajs/medusa into …
olivermrbl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@medusajs/medusa": patch | ||
"medusa-core-utils": patch | ||
--- | ||
|
||
jwt fix |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,12 @@ | ||
import { NextFunction, Request, RequestHandler, Response } from "express" | ||
import passport from "passport" | ||
import { Request, Response, NextFunction, RequestHandler } from "express" | ||
|
||
export default (): RequestHandler => { | ||
return (req: Request, res: Response, next: NextFunction): void => { | ||
passport.authenticate(["jwt", "bearer"], { session: false })(req, res, next) | ||
passport.authenticate(["admin-jwt", "bearer"], { session: false })( | ||
req, | ||
res, | ||
next | ||
) | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,19 @@ | ||
import { default as authenticateCustomer } from "./authenticate-customer" | ||
import { default as authenticate } from "./authenticate" | ||
import { default as normalizeQuery } from "./normalized-query" | ||
import { default as authenticateCustomer } from "./authenticate-customer" | ||
import { default as wrap } from "./await-middleware" | ||
import { default as normalizeQuery } from "./normalized-query" | ||
import { default as requireCustomerAuthentication } from "./require-customer-authentication" | ||
|
||
export { getRequestedBatchJob } from "./batch-job/get-requested-batch-job" | ||
export { canAccessBatchJob } from "./batch-job/can-access-batch-job" | ||
export { getRequestedBatchJob } from "./batch-job/get-requested-batch-job" | ||
export { doesConditionBelongToDiscount } from "./discount/does-condition-belong-to-discount" | ||
export { transformQuery } from "./transform-query" | ||
export { transformBody } from "./transform-body" | ||
export { transformQuery } from "./transform-query" | ||
|
||
export default { | ||
authenticate, | ||
authenticateCustomer, | ||
requireCustomerAuthentication, | ||
normalizeQuery, | ||
wrap, | ||
} |
12 changes: 12 additions & 0 deletions
12
packages/medusa/src/api/middlewares/require-customer-authentication.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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { NextFunction, Request, RequestHandler, Response } from "express" | ||
import passport from "passport" | ||
|
||
export default (): RequestHandler => { | ||
return (req: Request, res: Response, next: NextFunction): void => { | ||
passport.authenticate(["store-jwt", "bearer"], { session: false })( | ||
req, | ||
res, | ||
next | ||
) | ||
} | ||
} |
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
2 changes: 1 addition & 1 deletion
2
packages/medusa/src/api/routes/store/customers/create-address.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
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
2 changes: 1 addition & 1 deletion
2
packages/medusa/src/api/routes/store/customers/delete-address.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
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
6 changes: 3 additions & 3 deletions
6
packages/medusa/src/api/routes/store/customers/update-customer.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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thought(non-blocking): when this is called the
authenticateCustomer
middleware will already be applied. This means the JWT is parsed. We could just verify with a simpleif
that the customer has been parsed. Not an important change but just wanted to highlight that this might be duplicate work.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, I would just say that a user could use them independently and therefore I am not sure we should go with the idea that we know that internally it has already been parsed. Wdyt?