juspay / hyperswitch

An open source payments switch written in Rust to make payments fast, reliable and affordable
https://hyperswitch.io/
Apache License 2.0
11.02k stars 1.19k forks source link

fix(auth_methods): Add checks for duplicate `auth_method` in create API #5161

Closed ThisIsMani closed 1 day ago

ThisIsMani commented 4 days ago

Type of Change

Description

Currently create will accept and insert auth methods with same type and name, which shouldn't be possible. This PR fixes that.

Additional Changes

Motivation and Context

Closes #5160.

How did you test it?

curl --location 'http://localhost:8080/user/auth' \
--header 'Content-Type: application/json' \
--header 'api-key: test_admin' \
--data '{
    "owner_id": "org_qaamgpukifSyBG0AxtYA2x",
    "owner_type": "organization",
    "auth_method": {
        "auth_type": "open_id_connect",
        "private_config": {
            "base_url": "https://dev-28418517.okta.com",
            "client_id": "0oahmmwdmuFvv2pFo5d7",
            "client_secret": "-VIrZZeN_A0SdSpFykAUZ0iMJNpSYQyILcfUmYlmZaLaFK7uRayrEuSvhs-Um5IR"
        },
        "public_config": {
            "name": "okta"
        }
    },
    "allow_signup": false
}'

If this API is hit with same auth_type and name in public_config, then the API will throw the following error.

{
    "error": {
        "type": "invalid_request",
        "message": "User auth method already exists",
        "code": "UR_43"
    }
}

Checklist