hyperswitch icon indicating copy to clipboard operation
hyperswitch copied to clipboard

refactor: replace MerchantJwt with MerchantJwtWithProfileId in AuthenticationType

Open Rxbber-dxcky opened this issue 2 months ago • 16 comments

Type of Change

  • [ ] Bugfix
  • [ ] New feature
  • [ ] Enhancement
  • [x] Refactoring
  • [ ] Dependency updates
  • [ ] Documentation
  • [ ] CI/CD

Description

Replaced MerchantJwt with MerchantJwtWithProfileId in Authentication data. fixes #5937

Additional Changes

  • [ ] This PR modifies the API contract
  • [ ] This PR modifies the database schema
  • [ ] This PR modifies application configuration/environment variables

Motivation and Context

  1. Supports profile-based authentication
  2. Making the user_id field non-optional for better type safety
  3. Aligning with the new authentication flow requirements

How did you test it?

Pending

Checklist

  • [x] I formatted the code cargo +nightly fmt --all
  • [x] I addressed lints thrown by cargo clippy
  • [x] I reviewed the submitted code
  • [ ] I added unit tests for my changes where possible

Rxbber-dxcky avatar Sep 28 '25 07:09 Rxbber-dxcky

Review changes with  SemanticDiff

Changed Files
File Status
  crates/router/src/services/authentication.rs  31% smaller

semanticdiff-com[bot] avatar Sep 28 '25 07:09 semanticdiff-com[bot]

@ThisIsMani, how do i test the changes as the cargo test isnt working.

Rxbber-dxcky avatar Sep 28 '25 08:09 Rxbber-dxcky

@ThisIsMani, how do I test the implementation?

Rxbber-dxcky avatar Sep 29 '25 11:09 Rxbber-dxcky

Hey @Rxbber-dxcky, apologies for the delay.

Can you logging the auth_type variable and see the output in the following file.

https://github.com/juspay/hyperswitch/blob/9cd8f001f7360d9b8877fe94b9c185fc237e525c/crates/router/src/services/api.rs#L731

ThisIsMani avatar Sep 29 '25 11:09 ThisIsMani

Okay @ThisIsMani, I'll try to do that.

Rxbber-dxcky avatar Sep 29 '25 11:09 Rxbber-dxcky

@Rxbber-dxcky, you can trigger the log by doing any API call which uses JWT Auth... Let me know if you need more details.

ThisIsMani avatar Sep 29 '25 11:09 ThisIsMani

@Rxbber-dxcky, were you able to test your changes?

ThisIsMani avatar Oct 01 '25 10:10 ThisIsMani

@ThisIsMani , I used WSL to use cargo run and its execution gets stopped at router compiling. I think it's probably due to lack of memory. I'll try running it using an actual distro and get back to you.

Rxbber-dxcky avatar Oct 01 '25 11:10 Rxbber-dxcky

@ThisIsMani , I can compile the code but whenever I try to use an api call i get the api key invalid for JWT auth. I tried different ways to do it like creating a new user and generating the api key and using pre existing test api key and also tried to configure cookies. And nothing seems to work.

Rxbber-dxcky avatar Oct 03 '25 03:10 Rxbber-dxcky

@ThisIsMani, how do i do an api call ?

Rxbber-dxcky avatar Oct 05 '25 08:10 Rxbber-dxcky

Hey @Rxbber-dxcky, these are the steps to generate a valid JWT token. Let me know if you face issues.

Step 1:

curl --location 'https://live.hyperswitch.io/api/user/signup' \
--header 'Content-Type: application/json' \
--data '{
    "email": "email",
    "password": "password"
}'

You will get a token back.

Step 2:

curl --location 'https://live.hyperswitch.io/api/user/2fa/terminate?skip_two_factor_auth=true' \
--header 'Authorization: Bearer TOKEN_FROM_SIGNUP'

You will get another token back.

Using this token, you can hit any API that has JWTAuth.

ThisIsMani avatar Oct 07 '25 08:10 ThisIsMani

@ThisIsMani, thank you for the info

Rxbber-dxcky avatar Oct 09 '25 02:10 Rxbber-dxcky

@Rxbber-dxcky, were you able to test this? Let me know if you are still facing any issues.

ThisIsMani avatar Oct 17 '25 04:10 ThisIsMani

Sorry for the delay, @ThisIsMani I have some academic work going on that's why I've been inactive.I'll complete the task by the next weekend or before.

Rxbber-dxcky avatar Oct 18 '25 18:10 Rxbber-dxcky

@ThisIsMani, I have tested the implementation and the authentication is working fine.

Rxbber-dxcky avatar Oct 31 '25 15:10 Rxbber-dxcky

@ThisIsMani, the refactoring is good, I didnt get any errors while testing

Rxbber-dxcky avatar Nov 07 '25 14:11 Rxbber-dxcky