hyperswitch icon indicating copy to clipboard operation
hyperswitch copied to clipboard

refactor(authentication): modify auth for profiles and mca routes to `ApiKeyAuthWithMerchantIdFromRoute`

Open tsdk02 opened this issue 8 months ago • 1 comments

Type of Change

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

Description

Currently, the following routes use AdminApiAuthWithMerchantIdFromRoute for authentication:

  • Profile Create, Retrieve, Update
  • Merchant Connector Account Create, List, Retrieve, Update

This is being updated to a more appropriate auth layer: ApiKeyAuthWithMerchantIdFromRoute, which validates that the merchant_id in the API key matches the one in the route.

Additional Changes

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

Motivation and Context

These routes are profile and merchant-specific and can be accessed using the merchant's API key,

How did you test it?

Folowing are the endpoints which are changed:

Business Profile Create:

curl --location 'http://localhost:8080/account/merchant_1743057601/business_profile' \
--header 'Content-Type: application/json' \
--header 'api-key: dev_5xsUyXxOG9PXQcg3rFHb04PhdadsqtKltGAZ6ABoJBYXNSIqBlOuOouPin0bnvoY' \
--data '{
  "profile_name": "final-test"
}'

Business Profile Retrieve:

curl --location 'http://localhost:8080/account/merchant_1743057601/business_profile/pro_DaWH06Gvj0uyHu5TIzo9' \
--header 'api-key: dev_5xsUyXxOG9PXQcg3rFHb04PhdadsqtKltGAZ6ABoJBYXNSIqBlOuOouPin0bnvoY'

Business Profile Update:

curl --location 'http://localhost:8080/account/merchant_1743057601/business_profile/pro_r4qhkx1sVFsohrVEKuu2' \
--header 'Content-Type: application/json' \
--header 'api-key: dev_5xsUyXxOG9PXQcg3rFHb04PhdadsqtKltGAZ6ABoJBYXNSIqBlOuOouPin0bnvoY' \
--data '{
  "profile_name": "test-profile-auth2"
}'

Business Profile List:

curl --location 'http://localhost:8080/account/merchant_1743057601/business_profile' \
--header 'api-key: dev_5xsUyXxOG9PXQcg3rFHb04PhdadsqtKltGAZ6ABoJBYXNSIqBlOuOouPin0bnvoY'

Merchant Connector Account Create

curl --location 'http://localhost:8080/account/merchant_1743084798/connectors' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_awg6L6UKmUmNmvnJhYmgZpyWGKW2IfpT3Aq9huE9SicU5HbH0qk95MgQRMrjIdfT' \
--data '{
    "connector_type": "payment_processor",
    "profile_id": "pro_diCodYSThA3xAuDZ2rKV",
    "connector_name": "paypal_test",
    "connector_label": "paypal_test_default4",
    "disabled": false,
    "test_mode": true,
    "payment_methods_enabled": [
        {
            "payment_method": "card",
            "payment_method_types": [
                {
                    "payment_method_type": "debit",
                    "card_networks": [
                        "Mastercard"
                    ],
                    "minimum_amount": 0,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": false
                },
                {
                    "payment_method_type": "debit",
                    "card_networks": [
                        "Visa"
                    ],
                    "minimum_amount": 0,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": false
                },
                {
                    "payment_method_type": "debit",
                    "card_networks": [
                        "Interac"
                    ],
                    "minimum_amount": 0,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": false
                },
                {
                    "payment_method_type": "debit",
                    "card_networks": [
                        "AmericanExpress"
                    ],
                    "minimum_amount": 0,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": false
                },
                {
                    "payment_method_type": "debit",
                    "card_networks": [
                        "JCB"
                    ],
                    "minimum_amount": 0,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": false
                },
                {
                    "payment_method_type": "debit",
                    "card_networks": [
                        "DinersClub"
                    ],
                    "minimum_amount": 0,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": false
                },
                {
                    "payment_method_type": "debit",
                    "card_networks": [
                        "Discover"
                    ],
                    "minimum_amount": 0,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": false
                },
                {
                    "payment_method_type": "debit",
                    "card_networks": [
                        "CartesBancaires"
                    ],
                    "minimum_amount": 0,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": false
                },
                {
                    "payment_method_type": "debit",
                    "card_networks": [
                        "UnionPay"
                    ],
                    "minimum_amount": 0,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": false
                },
                {
                    "payment_method_type": "credit",
                    "card_networks": [
                        "Mastercard"
                    ],
                    "minimum_amount": 0,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": false
                },
                {
                    "payment_method_type": "credit",
                    "card_networks": [
                        "Visa"
                    ],
                    "minimum_amount": 0,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": false
                },
                {
                    "payment_method_type": "credit",
                    "card_networks": [
                        "Interac"
                    ],
                    "minimum_amount": 0,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": false
                },
                {
                    "payment_method_type": "credit",
                    "card_networks": [
                        "AmericanExpress"
                    ],
                    "minimum_amount": 0,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": false
                },
                {
                    "payment_method_type": "credit",
                    "card_networks": [
                        "JCB"
                    ],
                    "minimum_amount": 0,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": false
                },
                {
                    "payment_method_type": "credit",
                    "card_networks": [
                        "DinersClub"
                    ],
                    "minimum_amount": 0,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": false
                },
                {
                    "payment_method_type": "credit",
                    "card_networks": [
                        "Discover"
                    ],
                    "minimum_amount": 0,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": false
                },
                {
                    "payment_method_type": "credit",
                    "card_networks": [
                        "CartesBancaires"
                    ],
                    "minimum_amount": 0,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": false
                },
                {
                    "payment_method_type": "credit",
                    "card_networks": [
                        "UnionPay"
                    ],
                    "minimum_amount": 0,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": false
                }
            ]
        }
    ],
    "metadata": {},
    "connector_account_details": {
        "api_key": "test_key",
        "auth_type": "HeaderKey"
    },
    "additional_merchant_data": null,
    "status": "active",
    "pm_auth_config": null,
    "connector_wallets_details": null
}'

Merchant Connector Account Retrieve

curl --location 'http://localhost:8080/account/merchant_1743084798/connectors/mca_zAKHkuRqGOnduBqTHzlO' \
--header 'Accept: application/json' \
--header 'api-key: dev_awg6L6UKmUmNmvnJhYmgZpyWGKW2IfpT3Aq9huE9SicU5HbH0qk95MgQRMrjIdfT'

Merchant Connector Account Update

curl --location 'http://localhost:8080/account/merchant_1743084798/connectors/mca_zAKHkuRqGOnduBqTHzlO' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_awg6L6UKmUmNmvnJhYmgZpyWGKW2IfpT3Aq9huE9SicU5HbH0qk95MgQRMrjIdfT' \
--data '{
    "connector_type": "payment_processor",
    "connector_label": "paypal_test_default2",
    "disabled": false,
    "test_mode": true,
    "payment_methods_enabled": [
        {
            "payment_method": "card",
            "payment_method_types": [
                {
                    "payment_method_type": "debit",
                    "card_networks": [
                        "Mastercard"
                    ],
                    "minimum_amount": 0,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": false
                },
                {
                    "payment_method_type": "debit",
                    "card_networks": [
                        "Visa"
                    ],
                    "minimum_amount": 0,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": false
                },
                {
                    "payment_method_type": "debit",
                    "card_networks": [
                        "Interac"
                    ],
                    "minimum_amount": 0,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": false
                },
                {
                    "payment_method_type": "debit",
                    "card_networks": [
                        "AmericanExpress"
                    ],
                    "minimum_amount": 0,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": false
                },
                {
                    "payment_method_type": "debit",
                    "card_networks": [
                        "JCB"
                    ],
                    "minimum_amount": 0,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": false
                },
                {
                    "payment_method_type": "debit",
                    "card_networks": [
                        "DinersClub"
                    ],
                    "minimum_amount": 0,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": false
                },
                {
                    "payment_method_type": "debit",
                    "card_networks": [
                        "Discover"
                    ],
                    "minimum_amount": 0,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": false
                },
                {
                    "payment_method_type": "debit",
                    "card_networks": [
                        "CartesBancaires"
                    ],
                    "minimum_amount": 0,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": false
                },
                {
                    "payment_method_type": "debit",
                    "card_networks": [
                        "UnionPay"
                    ],
                    "minimum_amount": 0,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": false
                },
                {
                    "payment_method_type": "credit",
                    "card_networks": [
                        "Mastercard"
                    ],
                    "minimum_amount": 0,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": false
                },
                {
                    "payment_method_type": "credit",
                    "card_networks": [
                        "Visa"
                    ],
                    "minimum_amount": 0,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": false
                },
                {
                    "payment_method_type": "credit",
                    "card_networks": [
                        "Interac"
                    ],
                    "minimum_amount": 0,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": false
                },
                {
                    "payment_method_type": "credit",
                    "card_networks": [
                        "AmericanExpress"
                    ],
                    "minimum_amount": 0,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": false
                },
                {
                    "payment_method_type": "credit",
                    "card_networks": [
                        "JCB"
                    ],
                    "minimum_amount": 0,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": false
                },
                {
                    "payment_method_type": "credit",
                    "card_networks": [
                        "DinersClub"
                    ],
                    "minimum_amount": 0,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": false
                },
                {
                    "payment_method_type": "credit",
                    "card_networks": [
                        "Discover"
                    ],
                    "minimum_amount": 0,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": false
                },
                {
                    "payment_method_type": "credit",
                    "card_networks": [
                        "CartesBancaires"
                    ],
                    "minimum_amount": 0,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": false
                },
                {
                    "payment_method_type": "credit",
                    "card_networks": [
                        "UnionPay"
                    ],
                    "minimum_amount": 0,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": false
                }
            ]
        }
    ],
    "metadata": {},
    "additional_merchant_data": null,
    "status": "active",
    "pm_auth_config": null,
    "connector_wallets_details": null
}'

Merchant Connector Account List:

curl --location 'http://localhost:8080/account/merchant_1743084798/connectors' \
--header 'Content-Type: application/json' \
--header 'api-key: dev_awg6L6UKmUmNmvnJhYmgZpyWGKW2IfpT3Aq9huE9SicU5HbH0qk95MgQRMrjIdfT'

Merchant Connector Account Profile List:

curl --location 'http://localhost:8080/account/merchant_1743084798/profile/connectors' \
--header 'Content-Type: application/json' \
--header 'api-key: dev_awg6L6UKmUmNmvnJhYmgZpyWGKW2IfpT3Aq9huE9SicU5HbH0qk95MgQRMrjIdfT'

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

tsdk02 avatar Mar 27 '25 11:03 tsdk02

Review changes with  SemanticDiff

Changed Files
File Status
  crates/router/src/routes/admin.rs  0% smaller
  crates/router/src/routes/profiles.rs  0% smaller
  crates/router/src/services/authentication.rs  0% smaller
  cypress-tests-v2/cypress/support/commands.js  0% smaller
  cypress-tests/cypress/support/commands.js  0% smaller

semanticdiff-com[bot] avatar Mar 27 '25 11:03 semanticdiff-com[bot]