Support for proper Bearer/Non-session auth #4037
Replies: 6 comments 3 replies
-
Appreciate this proposal and the detailed description of what we could do better regarding authentication @dPreininger! You are more than welcome to submit these changes in a pull request, and we'll make sure to dedicate time for reviewing. Also, if I can assist in the implementation process, please let me know. Regarding breaking changes vs. backward compatibility, I'll let you decide. I am willing to accept both approaches. If you find keeping the API backward compatible too messy, I'd rather have us cut a minor bump introducing breaking changes. |
Beta Was this translation helpful? Give feedback.
-
I just want to comment on this bit:
The old Gatsby starter app was JAM stack, and the current official NextJS starter app CAN be used that way if desired, but that is not the only way people are using Medusa. It's important to keep in mind. Medusa's server-side storage of sessions is very important for my implementation. |
Beta Was this translation helpful? Give feedback.
-
I have opened a PR #4064 that implements these changes. |
Beta Was this translation helpful? Give feedback.
-
Hello @olivermrbl, I have opened a PR #4064 quite some time ago that implements the changes outline above. It seems as though the PR has gone unnoticed by the Medusa team. I am kindly asking you to assign someone from the core team to review the PR and provide feedback if something else needs to be changed before the PR is accepted and merged as the Medusa community seems to be excited for the changes proposed. Thanks, |
Beta Was this translation helpful? Give feedback.
-
I want to integrate medusa in flutter mobile and I need you to review this proposal please. |
Beta Was this translation helpful? Give feedback.
-
Is there progress on this? I can't think of a single reason that this type of API access authentication is NOT implemented here. Did they seriously not think people may like to use API key authentication? It baffles my mind. |
Beta Was this translation helpful? Give feedback.
-
Current implementation and flaws
Medusa currently uses session based authentication for Admin and Store APIs and is starting to user API tokens for Admin users.
Both session authentication ('admin-jwt' and 'store-jwt' passport strategies) and admin API token ('bearer' passport strategy) are flawed and are not following the standards:
Session auth flaws ('admin-jwt', 'store-jwt'):
create-session.ts
file:req.session.jwt = jwt.sign({ userId: result.user.id }, jwt_secret, { expiresIn: "24h" })
. As session object is stored only on the server, this could be achieved like so:req.session.userId = result.user.id; req.session.expires = { some date }
Bearer auth flaws ('bearer'):
Proposal
I propose a new implementation, which keeps all current functionalities, but adds a proper bearer auth for both store and admin domains. No breaking changes would be introduced.
I am willing to implement all of this myself. I have worked with one of the core contributors of Medusa, Adrien2p, in the past on his medusa-plugin-auth. I am familiar with the current state of Medusa auth code. I wouldn't need much guidance. The only responsibility core Medusa team would have is to review my PRs.
If my proposal is accepted, I am willing to contribute to Medusa authentication process in the future as well, implementing other features in the backlog, such as SSO support and support for user-defined passport strategies.
Thank you for reviewing this proposal.
Beta Was this translation helpful? Give feedback.
All reactions