Bug: [BUG] Internal Server Error when calling the Connector Integration



### Bug Description

Issue is caused when in any  Connector `auth_type ` we configure the `auth_type` which is not valid for that particular connector gets stored in the Db. Thus , whenever we call the Connector Integration we get a 500.
Reason: We're not validating the request body for `auth_type` . Thus it won't get validated and henceforth gets stored in the Db , whenever we try to get the Connector Integration  , it throws 500.

### Expected Behavior

It should validate the type of `auth_type` required by that particular connector , or else throw an error with respect to that connector.

### Actual Behavior

It throws internal server error.

### Steps To Reproduce

1. Create a Payment Connector
2. Pass an Invalid Auth_type
All these to be done in postman

### Context For The Bug

There is no validation for `connector auth_type` during  `merchant_connector_account` creation.

### Environment

Tested locally

### Have you spent some time to check if this bug has been raised before?

- [X] I checked and didn't find similar issue

### Have you read the Contributing Guidelines?

- [X] I have read the [Contributing Guidelines](https://github.com/juspay/hyperswitch/blob/main/docs/CONTRIBUTING.md)

### Are you willing to submit a PR?

Yes I am willing to submit a PR!
diff --git a/connector-template/mod.rs b/connector-template/mod.rs
index 653c28962b9..67745e8b4ce 100644
--- a/connector-template/mod.rs
+++ b/connector-template/mod.rs
@@ -77,6 +77,14 @@ impl ConnectorCommon for {{project-name | downcase | pascal_case}} {
     fn base_url<'a>(&self, connectors: &'a settings::Connectors) -> &'a str {
         connectors.{{project-name}}.base_url.as_ref()
     }
+    
+    fn validate_auth_type(
+        &self,
+        val: &types::ConnectorAuthType,
+    ) -> Result<(), error_stack::Report<errors::ConnectorError>> {
+        {{project-name | downcase}}::{{project-name | downcase | pascal_case}}AuthType::try_from(val)?;
+        Ok(())
+    }
 
     fn get_auth_header(&self, auth_type:&types::ConnectorAuthType)-> CustomResult<Vec<(String,request::Maskable<String>)>,errors::ConnectorError> {
         let auth =  {{project-name | downcase}}::{{project-name | downcase | pascal_case}}AuthType::try_from(auth_type)
diff --git a/crates/router/src/connector/aci.rs b/crates/router/src/connector/aci.rs
index 5bed999903d..6cc3f9e8329 100644
--- a/crates/router/src/connector/aci.rs
+++ b/crates/router/src/connector/aci.rs
@@ -34,6 +34,14 @@ impl ConnectorCommon for Aci {
         "application/x-www-form-urlencoded"
     }
 
+    fn validate_auth_type(
+        &self,
+        val: &types::ConnectorAuthType,
+    ) -> Result<(), error_stack::Report<errors::ConnectorError>> {
+        aci::AciAuthType::try_from(val)?;
+        Ok(())
+    }
+
     fn base_url<'a>(&self, connectors: &'a settings::Connectors) -> &'a str {
         connectors.aci.base_url.as_ref()
     }
diff --git a/crates/router/src/connector/adyen.rs b/crates/router/src/connector/adyen.rs
index 3d5b4d96091..5dcc38e46c3 100644
--- a/crates/router/src/connector/adyen.rs
+++ b/crates/router/src/connector/adyen.rs
@@ -49,6 +49,14 @@ impl ConnectorCommon for Adyen {
         )])
     }
 
+    fn validate_auth_type(
+        &self,
+        val: &types::ConnectorAuthType,
+    ) -> Result<(), error_stack::Report<errors::ConnectorError>> {
+        adyen::AdyenAuthType::try_from(val)?;
+        Ok(())
+    }
+
     fn base_url<'a>(&self, connectors: &'a settings::Connectors) -> &'a str {
         connectors.adyen.base_url.as_ref()
     }
diff --git a/crates/router/src/connector/airwallex.rs b/crates/router/src/connector/airwallex.rs
index 7cd5eb7124d..c8f253c4100 100644
--- a/crates/router/src/connector/airwallex.rs
+++ b/crates/router/src/connector/airwallex.rs
@@ -72,6 +72,14 @@ impl ConnectorCommon for Airwallex {
         connectors.airwallex.base_url.as_ref()
     }
 
+    fn validate_auth_type(
+        &self,
+        val: &types::ConnectorAuthType,
+    ) -> Result<(), error_stack::Report<errors::ConnectorError>> {
+        airwallex::AirwallexAuthType::try_from(val)?;
+        Ok(())
+    }
+
     fn build_error_response(
         &self,
         res: Response,
diff --git a/crates/router/src/connector/airwallex/transformers.rs b/crates/router/src/connector/airwallex/transformers.rs
index 68b990951bf..4e4dc6f8230 100644
--- a/crates/router/src/connector/airwallex/transformers.rs
+++ b/crates/router/src/connector/airwallex/transformers.rs
@@ -13,6 +13,25 @@ use crate::{
     types::{self, api, storage::enums},
 };
 
+pub struct AirwallexAuthType {
+    pub x_api_key: Secret<String>,
+    pub x_client_id: Secret<String>,
+}
+
+impl TryFrom<&types::ConnectorAuthType> for AirwallexAuthType {
+    type Error = error_stack::Report<errors::ConnectorError>;
+
+    fn try_from(auth_type: &types::ConnectorAuthType) -> Result<Self, Self::Error> {
+        if let types::ConnectorAuthType::BodyKey { api_key, key1 } = auth_type {
+            Ok(Self {
+                x_api_key: api_key.clone(),
+                x_client_id: key1.clone(),
+            })
+        } else {
+            Err(errors::ConnectorError::FailedToObtainAuthType)?
+        }
+    }
+}
 #[derive(Default, Debug, Serialize, Eq, PartialEq)]
 pub struct AirwallexIntentRequest {
     // Unique ID to be sent for each transaction/operation request to the connector
diff --git a/crates/router/src/connector/authorizedotnet.rs b/crates/router/src/connector/authorizedotnet.rs
index 6b7ed503f98..ca7f793abd7 100644
--- a/crates/router/src/connector/authorizedotnet.rs
+++ b/crates/router/src/connector/authorizedotnet.rs
@@ -52,6 +52,14 @@ impl ConnectorCommon for Authorizedotnet {
         "application/json"
     }
 
+    fn validate_auth_type(
+        &self,
+        val: &types::ConnectorAuthType,
+    ) -> Result<(), error_stack::Report<errors::ConnectorError>> {
+        authorizedotnet::MerchantAuthentication::try_from(val)?;
+        Ok(())
+    }
+
     fn base_url<'a>(&self, connectors: &'a settings::Connectors) -> &'a str {
         connectors.authorizedotnet.base_url.as_ref()
     }
diff --git a/crates/router/src/connector/authorizedotnet/transformers.rs b/crates/router/src/connector/authorizedotnet/transformers.rs
index aaaadd77edd..f1b1c3a452e 100644
--- a/crates/router/src/connector/authorizedotnet/transformers.rs
+++ b/crates/router/src/connector/authorizedotnet/transformers.rs
@@ -33,7 +33,7 @@ pub enum TransactionType {
 }
 #[derive(Debug, Serialize)]
 #[serde(rename_all = "camelCase")]
-struct MerchantAuthentication {
+pub struct MerchantAuthentication {
     name: Secret<String>,
     transaction_key: Secret<String>,
 }
diff --git a/crates/router/src/connector/bambora.rs b/crates/router/src/connector/bambora.rs
index e6e6b2ae93e..cd5e848403e 100644
--- a/crates/router/src/connector/bambora.rs
+++ b/crates/router/src/connector/bambora.rs
@@ -60,6 +60,14 @@ impl ConnectorCommon for Bambora {
         "application/json"
     }
 
+    fn validate_auth_type(
+        &self,
+        val: &types::ConnectorAuthType,
+    ) -> Result<(), error_stack::Report<errors::ConnectorError>> {
+        bambora::BamboraAuthType::try_from(val)?;
+        Ok(())
+    }
+
     fn base_url<'a>(&self, connectors: &'a settings::Connectors) -> &'a str {
         connectors.bambora.base_url.as_ref()
     }
diff --git a/crates/router/src/connector/bitpay.rs b/crates/router/src/connector/bitpay.rs
index eeb98020266..1e86764a42a 100644
--- a/crates/router/src/connector/bitpay.rs
+++ b/crates/router/src/connector/bitpay.rs
@@ -86,6 +86,14 @@ impl ConnectorCommon for Bitpay {
         "application/json"
     }
 
+    fn validate_auth_type(
+        &self,
+        val: &types::ConnectorAuthType,
+    ) -> Result<(), error_stack::Report<errors::ConnectorError>> {
+        bitpay::BitpayAuthType::try_from(val)?;
+        Ok(())
+    }
+
     fn base_url<'a>(&self, connectors: &'a settings::Connectors) -> &'a str {
         connectors.bitpay.base_url.as_ref()
     }
diff --git a/crates/router/src/connector/bluesnap.rs b/crates/router/src/connector/bluesnap.rs
index 296b641e351..1b88ea8523e 100644
--- a/crates/router/src/connector/bluesnap.rs
+++ b/crates/router/src/connector/bluesnap.rs
@@ -67,7 +67,13 @@ impl ConnectorCommon for Bluesnap {
     fn common_get_content_type(&self) -> &'static str {
         "application/json"
     }
-
+    fn validate_auth_type(
+        &self,
+        val: &types::ConnectorAuthType,
+    ) -> Result<(), error_stack::Report<errors::ConnectorError>> {
+        bluesnap::BluesnapAuthType::try_from(val)?;
+        Ok(())
+    }
     fn base_url<'a>(&self, connectors: &'a settings::Connectors) -> &'a str {
         connectors.bluesnap.base_url.as_ref()
     }
diff --git a/crates/router/src/connector/boku.rs b/crates/router/src/connector/boku.rs
index e0af2af95e1..70aa46e99bf 100644
--- a/crates/router/src/connector/boku.rs
+++ b/crates/router/src/connector/boku.rs
@@ -78,6 +78,13 @@ impl ConnectorCommon for Boku {
     fn common_get_content_type(&self) -> &'static str {
         "application/json"
     }
+    fn validate_auth_type(
+        &self,
+        val: &types::ConnectorAuthType,
+    ) -> Result<(), error_stack::Report<errors::ConnectorError>> {
+        boku::BokuAuthType::try_from(val)?;
+        Ok(())
+    }
 
     fn base_url<'a>(&self, connectors: &'a settings::Connectors) -> &'a str {
         connectors.boku.base_url.as_ref()
diff --git a/crates/router/src/connector/braintree.rs b/crates/router/src/connector/braintree.rs
index 717bf1747cd..3c2838f74b0 100644
--- a/crates/router/src/connector/braintree.rs
+++ b/crates/router/src/connector/braintree.rs
@@ -34,6 +34,14 @@ impl ConnectorCommon for Braintree {
         connectors.braintree.base_url.as_ref()
     }
 
+    fn validate_auth_type(
+        &self,
+        val: &types::ConnectorAuthType,
+    ) -> Result<(), error_stack::Report<errors::ConnectorError>> {
+        braintree::BraintreeAuthType::try_from(val)?;
+        Ok(())
+    }
+
     fn get_auth_header(
         &self,
         auth_type: &types::ConnectorAuthType,
diff --git a/crates/router/src/connector/cashtocode.rs b/crates/router/src/connector/cashtocode.rs
index 249ca3fe61d..c14c666a7a5 100644
--- a/crates/router/src/connector/cashtocode.rs
+++ b/crates/router/src/connector/cashtocode.rs
@@ -97,6 +97,14 @@ impl ConnectorCommon for Cashtocode {
         "application/json"
     }
 
+    fn validate_auth_type(
+        &self,
+        val: &types::ConnectorAuthType,
+    ) -> Result<(), error_stack::Report<errors::ConnectorError>> {
+        cashtocode::CashtocodeAuthType::try_from(val)?;
+        Ok(())
+    }
+
     fn base_url<'a>(&self, connectors: &'a settings::Connectors) -> &'a str {
         connectors.cashtocode.base_url.as_ref()
     }
diff --git a/crates/router/src/connector/checkout.rs b/crates/router/src/connector/checkout.rs
index c9d4edce7ea..42b29d24837 100644
--- a/crates/router/src/connector/checkout.rs
+++ b/crates/router/src/connector/checkout.rs
@@ -62,7 +62,13 @@ impl ConnectorCommon for Checkout {
     fn common_get_content_type(&self) -> &'static str {
         "application/json"
     }
-
+    fn validate_auth_type(
+        &self,
+        val: &types::ConnectorAuthType,
+    ) -> Result<(), error_stack::Report<errors::ConnectorError>> {
+        checkout::CheckoutAuthType::try_from(val)?;
+        Ok(())
+    }
     fn get_auth_header(
         &self,
         auth_type: &types::ConnectorAuthType,
diff --git a/crates/router/src/connector/coinbase.rs b/crates/router/src/connector/coinbase.rs
index 1d4d5764e26..a4bbf77ab47 100644
--- a/crates/router/src/connector/coinbase.rs
+++ b/crates/router/src/connector/coinbase.rs
@@ -76,6 +76,14 @@ impl ConnectorCommon for Coinbase {
         "application/json"
     }
 
+    fn validate_auth_type(
+        &self,
+        val: &types::ConnectorAuthType,
+    ) -> Result<(), error_stack::Report<errors::ConnectorError>> {
+        coinbase::CoinbaseAuthType::try_from(val)?;
+        Ok(())
+    }
+
     fn base_url<'a>(&self, connectors: &'a settings::Connectors) -> &'a str {
         connectors.coinbase.base_url.as_ref()
     }
diff --git a/crates/router/src/connector/cryptopay.rs b/crates/router/src/connector/cryptopay.rs
index 4fa8c4e8da5..39bc441192a 100644
--- a/crates/router/src/connector/cryptopay.rs
+++ b/crates/router/src/connector/cryptopay.rs
@@ -133,6 +133,14 @@ impl ConnectorCommon for Cryptopay {
         "application/json"
     }
 
+    fn validate_auth_type(
+        &self,
+        val: &types::ConnectorAuthType,
+    ) -> Result<(), error_stack::Report<errors::ConnectorError>> {
+        cryptopay::CryptopayAuthType::try_from(val)?;
+        Ok(())
+    }
+
     fn base_url<'a>(&self, connectors: &'a settings::Connectors) -> &'a str {
         connectors.cryptopay.base_url.as_ref()
     }
diff --git a/crates/router/src/connector/cybersource.rs b/crates/router/src/connector/cybersource.rs
index ba8b35964f3..e9e51df5b59 100644
--- a/crates/router/src/connector/cybersource.rs
+++ b/crates/router/src/connector/cybersource.rs
@@ -88,6 +88,13 @@ impl ConnectorCommon for Cybersource {
         "application/json;charset=utf-8"
     }
 
+    fn validate_auth_type(
+        &self,
+        val: &types::ConnectorAuthType,
+    ) -> Result<(), error_stack::Report<errors::ConnectorError>> {
+        cybersource::CybersourceAuthType::try_from(val)?;
+        Ok(())
+    }
     fn base_url<'a>(&self, connectors: &'a settings::Connectors) -> &'a str {
         connectors.cybersource.base_url.as_ref()
     }
diff --git a/crates/router/src/connector/dlocal.rs b/crates/router/src/connector/dlocal.rs
index be0855e4352..02be442c752 100644
--- a/crates/router/src/connector/dlocal.rs
+++ b/crates/router/src/connector/dlocal.rs
@@ -111,6 +111,14 @@ impl ConnectorCommon for Dlocal {
         "application/json"
     }
 
+    fn validate_auth_type(
+        &self,
+        val: &types::ConnectorAuthType,
+    ) -> Result<(), error_stack::Report<errors::ConnectorError>> {
+        dlocal::DlocalAuthType::try_from(val)?;
+        Ok(())
+    }
+
     fn base_url<'a>(&self, connectors: &'a settings::Connectors) -> &'a str {
         connectors.dlocal.base_url.as_ref()
     }
diff --git a/crates/router/src/connector/dummyconnector.rs b/crates/router/src/connector/dummyconnector.rs
index 80787b35d19..3506e2ecb37 100644
--- a/crates/router/src/connector/dummyconnector.rs
+++ b/crates/router/src/connector/dummyconnector.rs
@@ -90,6 +90,14 @@ impl<const T: u8> ConnectorCommon for DummyConnector<T> {
         "application/json"
     }
 
+    fn validate_auth_type(
+        &self,
+        val: &types::ConnectorAuthType,
+    ) -> Result<(), error_stack::Report<errors::ConnectorError>> {
+        dummyconnector::DummyConnectorAuthType::try_from(val)?;
+        Ok(())
+    }
+
     fn base_url<'a>(&self, connectors: &'a settings::Connectors) -> &'a str {
         connectors.dummyconnector.base_url.as_ref()
     }
diff --git a/crates/router/src/connector/fiserv.rs b/crates/router/src/connector/fiserv.rs
index 25a593f3ffe..921cd1fc91d 100644
--- a/crates/router/src/connector/fiserv.rs
+++ b/crates/router/src/connector/fiserv.rs
@@ -105,6 +105,14 @@ impl ConnectorCommon for Fiserv {
         "application/json"
     }
 
+    fn validate_auth_type(
+        &self,
+        val: &types::ConnectorAuthType,
+    ) -> Result<(), error_stack::Report<errors::ConnectorError>> {
+        fiserv::FiservAuthType::try_from(val)?;
+        Ok(())
+    }
+
     fn base_url<'a>(&self, connectors: &'a settings::Connectors) -> &'a str {
         connectors.fiserv.base_url.as_ref()
     }
diff --git a/crates/router/src/connector/forte.rs b/crates/router/src/connector/forte.rs
index 5dde831071b..b184a4364d8 100644
--- a/crates/router/src/connector/forte.rs
+++ b/crates/router/src/connector/forte.rs
@@ -79,6 +79,13 @@ impl ConnectorCommon for Forte {
     fn common_get_content_type(&self) -> &'static str {
         "application/json"
     }
+    fn validate_auth_type(
+        &self,
+        val: &types::ConnectorAuthType,
+    ) -> Result<(), error_stack::Report<errors::ConnectorError>> {
+        forte::ForteAuthType::try_from(val)?;
+        Ok(())
+    }
 
     fn base_url<'a>(&self, connectors: &'a settings::Connectors) -> &'a str {
         connectors.forte.base_url.as_ref()
diff --git a/crates/router/src/connector/globalpay.rs b/crates/router/src/connector/globalpay.rs
index e15da504a8b..a233da05a33 100644
--- a/crates/router/src/connector/globalpay.rs
+++ b/crates/router/src/connector/globalpay.rs
@@ -15,6 +15,7 @@ use self::{
         GlobalpayPaymentsResponse, GlobalpayRefreshTokenErrorResponse,
         GlobalpayRefreshTokenResponse,
     },
+    transformers::GlobalpayAuthType,
 };
 use super::utils::RefundsRequestData;
 use crate::{
@@ -78,6 +79,14 @@ impl ConnectorCommon for Globalpay {
         "application/json"
     }
 
+    fn validate_auth_type(
+        &self,
+        val: &types::ConnectorAuthType,
+    ) -> Result<(), error_stack::Report<errors::ConnectorError>> {
+        GlobalpayAuthType::try_from(val)?;
+        Ok(())
+    }
+
     fn base_url<'a>(&self, connectors: &'a settings::Connectors) -> &'a str {
         connectors.globalpay.base_url.as_ref()
     }
diff --git a/crates/router/src/connector/globepay.rs b/crates/router/src/connector/globepay.rs
index bd3bfdb920a..29e4eaa704d 100644
--- a/crates/router/src/connector/globepay.rs
+++ b/crates/router/src/connector/globepay.rs
@@ -103,6 +103,13 @@ impl ConnectorCommon for Globepay {
     fn common_get_content_type(&self) -> &'static str {
         "application/json"
     }
+    fn validate_auth_type(
+        &self,
+        val: &types::ConnectorAuthType,
+    ) -> Result<(), error_stack::Report<errors::ConnectorError>> {
+        globepay::GlobepayAuthType::try_from(val)?;
+        Ok(())
+    }
 
     fn base_url<'a>(&self, connectors: &'a settings::Connectors) -> &'a str {
         connectors.globepay.base_url.as_ref()
diff --git a/crates/router/src/connector/iatapay.rs b/crates/router/src/connector/iatapay.rs
index f3f5a4eb126..4b104cde737 100644
--- a/crates/router/src/connector/iatapay.rs
+++ b/crates/router/src/connector/iatapay.rs
@@ -90,6 +90,14 @@ impl ConnectorCommon for Iatapay {
         "application/json"
     }
 
+    fn validate_auth_type(
+        &self,
+        val: &types::ConnectorAuthType,
+    ) -> Result<(), error_stack::Report<errors::ConnectorError>> {
+        iatapay::IatapayAuthType::try_from(val)?;
+        Ok(())
+    }
+
     fn base_url<'a>(&self, connectors: &'a settings::Connectors) -> &'a str {
         connectors.iatapay.base_url.as_ref()
     }
diff --git a/crates/router/src/connector/klarna.rs b/crates/router/src/connector/klarna.rs
index 73d6f17248c..2d9fbafbdb9 100644
--- a/crates/router/src/connector/klarna.rs
+++ b/crates/router/src/connector/klarna.rs
@@ -34,6 +34,14 @@ impl ConnectorCommon for Klarna {
         "application/json"
     }
 
+    fn validate_auth_type(
+        &self,
+        val: &types::ConnectorAuthType,
+    ) -> Result<(), error_stack::Report<errors::ConnectorError>> {
+        klarna::KlarnaAuthType::try_from(val)?;
+        Ok(())
+    }
+
     fn base_url<'a>(&self, connectors: &'a settings::Connectors) -> &'a str {
         connectors.klarna.base_url.as_ref()
     }
diff --git a/crates/router/src/connector/mollie.rs b/crates/router/src/connector/mollie.rs
index 46385e2ec6c..042c593dcf0 100644
--- a/crates/router/src/connector/mollie.rs
+++ b/crates/router/src/connector/mollie.rs
@@ -65,6 +65,13 @@ impl ConnectorCommon for Mollie {
     fn base_url<'a>(&self, connectors: &'a settings::Connectors) -> &'a str {
         connectors.mollie.base_url.as_ref()
     }
+    fn validate_auth_type(
+        &self,
+        val: &types::ConnectorAuthType,
+    ) -> Result<(), error_stack::Report<errors::ConnectorError>> {
+        mollie::MollieAuthType::try_from(val)?;
+        Ok(())
+    }
 
     fn get_auth_header(
         &self,
diff --git a/crates/router/src/connector/multisafepay.rs b/crates/router/src/connector/multisafepay.rs
index 07daef20e21..143fdf04746 100644
--- a/crates/router/src/connector/multisafepay.rs
+++ b/crates/router/src/connector/multisafepay.rs
@@ -48,6 +48,14 @@ impl ConnectorCommon for Multisafepay {
         "application/json"
     }
 
+    fn validate_auth_type(
+        &self,
+        val: &types::ConnectorAuthType,
+    ) -> Result<(), error_stack::Report<errors::ConnectorError>> {
+        multisafepay::MultisafepayAuthType::try_from(val)?;
+        Ok(())
+    }
+
     fn base_url<'a>(&self, connectors: &'a settings::Connectors) -> &'a str {
         connectors.multisafepay.base_url.as_ref()
     }
diff --git a/crates/router/src/connector/nexinets.rs b/crates/router/src/connector/nexinets.rs
index 2d90c2c4c18..e9d8a062820 100644
--- a/crates/router/src/connector/nexinets.rs
+++ b/crates/router/src/connector/nexinets.rs
@@ -76,6 +76,13 @@ impl ConnectorCommon for Nexinets {
     fn common_get_content_type(&self) -> &'static str {
         "application/json"
     }
+    fn validate_auth_type(
+        &self,
+        val: &types::ConnectorAuthType,
+    ) -> Result<(), error_stack::Report<errors::ConnectorError>> {
+        nexinets::NexinetsAuthType::try_from(val)?;
+        Ok(())
+    }
 
     fn base_url<'a>(&self, connectors: &'a settings::Connectors) -> &'a str {
         connectors.nexinets.base_url.as_ref()
diff --git a/crates/router/src/connector/nmi.rs b/crates/router/src/connector/nmi.rs
index 37fc6e5cf8e..c6b6241973f 100644
--- a/crates/router/src/connector/nmi.rs
+++ b/crates/router/src/connector/nmi.rs
@@ -59,6 +59,13 @@ impl ConnectorCommon for Nmi {
     fn base_url<'a>(&self, connectors: &'a settings::Connectors) -> &'a str {
         connectors.nmi.base_url.as_ref()
     }
+    fn validate_auth_type(
+        &self,
+        val: &types::ConnectorAuthType,
+    ) -> Result<(), error_stack::Report<errors::ConnectorError>> {
+        nmi::NmiAuthType::try_from(val)?;
+        Ok(())
+    }
 
     fn build_error_response(
         &self,
diff --git a/crates/router/src/connector/noon.rs b/crates/router/src/connector/noon.rs
index 22c778334e7..fce88d86f97 100644
--- a/crates/router/src/connector/noon.rs
+++ b/crates/router/src/connector/noon.rs
@@ -86,6 +86,13 @@ impl ConnectorCommon for Noon {
         "application/json"
     }
 
+    fn validate_auth_type(
+        &self,
+        val: &types::ConnectorAuthType,
+    ) -> Result<(), error_stack::Report<errors::ConnectorError>> {
+        noon::NoonAuthType::try_from(val)?;
+        Ok(())
+    }
     fn base_url<'a>(&self, connectors: &'a settings::Connectors) -> &'a str {
         connectors.noon.base_url.as_ref()
     }
diff --git a/crates/router/src/connector/nuvei.rs b/crates/router/src/connector/nuvei.rs
index 560eea6f09d..6cbb44e5873 100644
--- a/crates/router/src/connector/nuvei.rs
+++ b/crates/router/src/connector/nuvei.rs
@@ -56,7 +56,13 @@ impl ConnectorCommon for Nuvei {
     fn common_get_content_type(&self) -> &'static str {
         "application/json"
     }
-
+    fn validate_auth_type(
+        &self,
+        val: &types::ConnectorAuthType,
+    ) -> Result<(), error_stack::Report<errors::ConnectorError>> {
+        nuvei::NuveiAuthType::try_from(val)?;
+        Ok(())
+    }
     fn base_url<'a>(&self, connectors: &'a settings::Connectors) -> &'a str {
         connectors.nuvei.base_url.as_ref()
     }
diff --git a/crates/router/src/connector/opayo.rs b/crates/router/src/connector/opayo.rs
index 4203bd71522..2716796837f 100644
--- a/crates/router/src/connector/opayo.rs
+++ b/crates/router/src/connector/opayo.rs
@@ -76,6 +76,14 @@ impl ConnectorCommon for Opayo {
         "application/json"
     }
 
+    fn validate_auth_type(
+        &self,
+        val: &types::ConnectorAuthType,
+    ) -> Result<(), error_stack::Report<errors::ConnectorError>> {
+        opayo::OpayoAuthType::try_from(val)?;
+        Ok(())
+    }
+
     fn base_url<'a>(&self, connectors: &'a settings::Connectors) -> &'a str {
         connectors.opayo.base_url.as_ref()
     }
diff --git a/crates/router/src/connector/opennode.rs b/crates/router/src/connector/opennode.rs
index 36eba82093a..c4f75d7fbab 100644
--- a/crates/router/src/connector/opennode.rs
+++ b/crates/router/src/connector/opennode.rs
@@ -75,6 +75,13 @@ impl ConnectorCommon for Opennode {
     fn common_get_content_type(&self) -> &'static str {
         "application/json"
     }
+    fn validate_auth_type(
+        &self,
+        val: &types::ConnectorAuthType,
+    ) -> Result<(), error_stack::Report<errors::ConnectorError>> {
+        opennode::OpennodeAuthType::try_from(val)?;
+        Ok(())
+    }
 
     fn base_url<'a>(&self, connectors: &'a settings::Connectors) -> &'a str {
         connectors.opennode.base_url.as_ref()
diff --git a/crates/router/src/connector/payeezy.rs b/crates/router/src/connector/payeezy.rs
index d210b04df27..04f58538423 100644
--- a/crates/router/src/connector/payeezy.rs
+++ b/crates/router/src/connector/payeezy.rs
@@ -91,6 +91,13 @@ impl ConnectorCommon for Payeezy {
     fn common_get_content_type(&self) -> &'static str {
         "application/json"
     }
+    fn validate_auth_type(
+        &self,
+        val: &types::ConnectorAuthType,
+    ) -> Result<(), error_stack::Report<errors::ConnectorError>> {
+        payeezy::PayeezyAuthType::try_from(val)?;
+        Ok(())
+    }
 
     fn base_url<'a>(&self, connectors: &'a settings::Connectors) -> &'a str {
         connectors.payeezy.base_url.as_ref()
diff --git a/crates/router/src/connector/payme.rs b/crates/router/src/connector/payme.rs
index b33b78ee5cd..6d5bda6e2b8 100644
--- a/crates/router/src/connector/payme.rs
+++ b/crates/router/src/connector/payme.rs
@@ -73,6 +73,13 @@ impl ConnectorCommon for Payme {
     fn common_get_content_type(&self) -> &'static str {
         "application/json"
     }
+    fn validate_auth_type(
+        &self,
+        val: &types::ConnectorAuthType,
+    ) -> Result<(), error_stack::Report<errors::ConnectorError>> {
+        payme::PaymeAuthType::try_from(val)?;
+        Ok(())
+    }
 
     fn base_url<'a>(&self, connectors: &'a settings::Connectors) -> &'a str {
         connectors.payme.base_url.as_ref()
diff --git a/crates/router/src/connector/paypal.rs b/crates/router/src/connector/paypal.rs
index dc6a70431a0..ec74a8f0214 100644
--- a/crates/router/src/connector/paypal.rs
+++ b/crates/router/src/connector/paypal.rs
@@ -150,6 +150,13 @@ impl ConnectorCommon for Paypal {
     fn common_get_content_type(&self) -> &'static str {
         "application/json"
     }
+    fn validate_auth_type(
+        &self,
+        val: &types::ConnectorAuthType,
+    ) -> Result<(), error_stack::Report<errors::ConnectorError>> {
+        paypal::PaypalAuthType::try_from(val)?;
+        Ok(())
+    }
 
     fn base_url<'a>(&self, connectors: &'a settings::Connectors) -> &'a str {
         connectors.paypal.base_url.as_ref()
diff --git a/crates/router/src/connector/payu.rs b/crates/router/src/connector/payu.rs
index 1b5bc904bfc..e6a2afbf995 100644
--- a/crates/router/src/connector/payu.rs
+++ b/crates/router/src/connector/payu.rs
@@ -63,6 +63,14 @@ impl ConnectorCommon for Payu {
         "application/json"
     }
 
+    fn validate_auth_type(
+        &self,
+        val: &types::ConnectorAuthType,
+    ) -> Result<(), error_stack::Report<errors::ConnectorError>> {
+        payu::PayuAuthType::try_from(val)?;
+        Ok(())
+    }
+
     fn base_url<'a>(&self, connectors: &'a settings::Connectors) -> &'a str {
         connectors.payu.base_url.as_ref()
     }
diff --git a/crates/router/src/connector/powertranz.rs b/crates/router/src/connector/powertranz.rs
index 252f8479887..f980b9d117b 100644
--- a/crates/router/src/connector/powertranz.rs
+++ b/crates/router/src/connector/powertranz.rs
@@ -84,6 +84,14 @@ impl ConnectorCommon for Powertranz {
         "application/json"
     }
 
+    fn validate_auth_type(
+        &self,
+        val: &types::ConnectorAuthType,
+    ) -> Result<(), error_stack::Report<errors::ConnectorError>> {
+        powertranz::PowertranzAuthType::try_from(val)?;
+        Ok(())
+    }
+
     fn base_url<'a>(&self, connectors: &'a settings::Connectors) -> &'a str {
         connectors.powertranz.base_url.as_ref()
     }
diff --git a/crates/router/src/connector/rapyd.rs b/crates/router/src/connector/rapyd.rs
index b1e814afb4f..f6e8056505f 100644
--- a/crates/router/src/connector/rapyd.rs
+++ b/crates/router/src/connector/rapyd.rs
@@ -67,6 +67,14 @@ impl ConnectorCommon for Rapyd {
         "application/json"
     }
 
+    fn validate_auth_type(
+        &self,
+        val: &types::ConnectorAuthType,
+    ) -> Result<(), error_stack::Report<errors::ConnectorError>> {
+        rapyd::RapydAuthType::try_from(val)?;
+        Ok(())
+    }
+
     fn base_url<'a>(&self, connectors: &'a settings::Connectors) -> &'a str {
         connectors.rapyd.base_url.as_ref()
     }
diff --git a/crates/router/src/connector/shift4.rs b/crates/router/src/connector/shift4.rs
index ba0e655977d..b66dff85108 100644
--- a/crates/router/src/connector/shift4.rs
+++ b/crates/router/src/connector/shift4.rs
@@ -64,6 +64,14 @@ impl ConnectorCommon for Shift4 {
         "application/json"
     }
 
+    fn validate_auth_type(
+        &self,
+        val: &types::ConnectorAuthType,
+    ) -> Result<(), error_stack::Report<errors::ConnectorError>> {
+        shift4::Shift4AuthType::try_from(val)?;
+        Ok(())
+    }
+
     fn base_url<'a>(&self, connectors: &'a settings::Connectors) -> &'a str {
         connectors.shift4.base_url.as_ref()
     }
diff --git a/crates/router/src/connector/stax.rs b/crates/router/src/connector/stax.rs
index 86a1e7196dc..460539930bb 100644
--- a/crates/router/src/connector/stax.rs
+++ b/crates/router/src/connector/stax.rs
@@ -73,6 +73,13 @@ impl ConnectorCommon for Stax {
     fn id(&self) -> &'static str {
         "stax"
     }
+    fn validate_auth_type(
+        &self,
+        val: &types::ConnectorAuthType,
+    ) -> Result<(), error_stack::Report<errors::ConnectorError>> {
+        stax::StaxAuthType::try_from(val)?;
+        Ok(())
+    }
 
     fn common_get_content_type(&self) -> &'static str {
         "application/json"
diff --git a/crates/router/src/connector/stripe.rs b/crates/router/src/connector/stripe.rs
index a717022e788..6703e54293b 100644
--- a/crates/router/src/connector/stripe.rs
+++ b/crates/router/src/connector/stripe.rs
@@ -1,4 +1,4 @@
-mod transformers;
+pub mod transformers;
 
 use std::{collections::HashMap, fmt::Debug, ops::Deref};
 
@@ -40,6 +40,14 @@ impl ConnectorCommon for Stripe {
         "application/x-www-form-urlencoded"
     }
 
+    fn validate_auth_type(
+        &self,
+        val: &types::ConnectorAuthType,
+    ) -> Result<(), error_stack::Report<errors::ConnectorError>> {
+        stripe::StripeAuthType::try_from(val)?;
+        Ok(())
+    }
+
     fn base_url<'a>(&self, connectors: &'a settings::Connectors) -> &'a str {
         // &self.base_url
         connectors.stripe.base_url.as_ref()
diff --git a/crates/router/src/connector/trustpay.rs b/crates/router/src/connector/trustpay.rs
index e0a039e579a..267ed06ab9a 100644
--- a/crates/router/src/connector/trustpay.rs
+++ b/crates/router/src/connector/trustpay.rs
@@ -81,6 +81,14 @@ impl ConnectorCommon for Trustpay {
         "application/x-www-form-urlencoded"
     }
 
+    fn validate_auth_type(
+        &self,
+        val: &types::ConnectorAuthType,
+    ) -> Result<(), error_stack::Report<errors::ConnectorError>> {
+        trustpay::TrustpayAuthType::try_from(val)?;
+        Ok(())
+    }
+
     fn base_url<'a>(&self, connectors: &'a settings::Connectors) -> &'a str {
         connectors.trustpay.base_url.as_ref()
     }
diff --git a/crates/router/src/connector/tsys.rs b/crates/router/src/connector/tsys.rs
index 222e20926de..5613cd439ea 100644
--- a/crates/router/src/connector/tsys.rs
+++ b/crates/router/src/connector/tsys.rs
@@ -73,6 +73,14 @@ impl ConnectorCommon for Tsys {
         "application/json"
     }
 
+    fn validate_auth_type(
+        &self,
+        val: &types::ConnectorAuthType,
+    ) -> Result<(), error_stack::Report<errors::ConnectorError>> {
+        tsys::TsysAuthType::try_from(val)?;
+        Ok(())
+    }
+
     fn base_url<'a>(&self, connectors: &'a settings::Connectors) -> &'a str {
         connectors.tsys.base_url.as_ref()
     }
diff --git a/crates/router/src/connector/wise.rs b/crates/router/src/connector/wise.rs
index 7d1f4b2786c..7519697e773 100644
--- a/crates/router/src/connector/wise.rs
+++ b/crates/router/src/connector/wise.rs
@@ -59,6 +59,13 @@ impl ConnectorCommon for Wise {
     fn id(&self) -> &'static str {
         "wise"
     }
+    fn validate_auth_type(
+        &self,
+        val: &types::ConnectorAuthType,
+    ) -> Result<(), error_stack::Report<errors::ConnectorError>> {
+        wise::WiseAuthType::try_from(val)?;
+        Ok(())
+    }
 
     fn get_auth_header(
         &self,
diff --git a/crates/router/src/connector/worldline.rs b/crates/router/src/connector/worldline.rs
index b356945fc68..cb07e7a1a52 100644
--- a/crates/router/src/connector/worldline.rs
+++ b/crates/router/src/connector/worldline.rs
@@ -116,6 +116,14 @@ impl ConnectorCommon for Worldline {
         connectors.worldline.base_url.as_ref()
     }
 
+    fn validate_auth_type(
+        &self,
+        val: &types::ConnectorAuthType,
+    ) -> Result<(), error_stack::Report<errors::ConnectorError>> {
+        worldline::AuthType::try_from(val)?;
+        Ok(())
+    }
+
     fn build_error_response(
         &self,
         res: types::Response,
diff --git a/crates/router/src/connector/worldpay.rs b/crates/router/src/connector/worldpay.rs
index 12f5abf6b38..ad6962e0fbc 100644
--- a/crates/router/src/connector/worldpay.rs
+++ b/crates/router/src/connector/worldpay.rs
@@ -59,6 +59,14 @@ impl ConnectorCommon for Worldpay {
         "application/vnd.worldpay.payments-v6+json"
     }
 
+    fn validate_auth_type(
+        &self,
+        val: &types::ConnectorAuthType,
+    ) -> Result<(), error_stack::Report<errors::ConnectorError>> {
+        worldpay::WorldpayAuthType::try_from(val)?;
+        Ok(())
+    }
+
     fn base_url<'a>(&self, connectors: &'a settings::Connectors) -> &'a str {
         connectors.worldpay.base_url.as_ref()
     }
diff --git a/crates/router/src/connector/zen.rs b/crates/router/src/connector/zen.rs
index a583e0d8340..43e392c2ad8 100644
--- a/crates/router/src/connector/zen.rs
+++ b/crates/router/src/connector/zen.rs
@@ -83,6 +83,13 @@ impl ConnectorCommon for Zen {
     fn common_get_content_type(&self) -> &'static str {
         mime::APPLICATION_JSON.essence_str()
     }
+    fn validate_auth_type(
+        &self,
+        val: &types::ConnectorAuthType,
+    ) -> Result<(), error_stack::Report<errors::ConnectorError>> {
+        zen::ZenAuthType::try_from(val)?;
+        Ok(())
+    }
 
     fn base_url<'a>(&self, connectors: &'a settings::Connectors) -> &'a str {
         connectors.zen.base_url.as_ref()
diff --git a/crates/router/src/core/admin.rs b/crates/router/src/core/admin.rs
index c8efdf5397f..320c59c84d7 100644
--- a/crates/router/src/core/admin.rs
+++ b/crates/router/src/core/admin.rs
@@ -16,10 +16,11 @@ use crate::{
         payments::helpers,
     },
     db::StorageInterface,
-    routes::metrics,
+    routes::{metrics, AppState},
     services::{self, api as service_api},
     types::{
-        self, api,
+        self,
+        api::{self, ConnectorData},
         domain::{
             self,
             types::{self as domain_types, AsyncLift},
@@ -440,12 +441,16 @@ fn validate_certificate_in_mca_metadata(
 }
 
 pub async fn create_payment_connector(
-    store: &dyn StorageInterface,
+    state: &AppState,
     req: api::MerchantConnectorCreate,
     merchant_id: &String,
 ) -> RouterResponse<api_models::admin::MerchantConnectorResponse> {
-    let key_store = store
-        .get_merchant_key_store_by_merchant_id(merchant_id, &store.get_master_key().to_vec().into())
+    let key_store = state
+        .store
+        .get_merchant_key_store_by_merchant_id(
+            merchant_id,
+            &state.store.get_master_key().to_vec().into(),
+        )
         .await
         .to_not_found_response(errors::ApiErrorResponse::MerchantAccountNotFound)?;
 
@@ -454,7 +459,8 @@ pub async fn create_payment_connector(
         .map(validate_certificate_in_mca_metadata)
         .transpose()?;
 
-    let merchant_account = store
+    let merchant_account = state
+        .store
         .find_merchant_account_by_merchant_id(merchant_id, &key_store)
         .await
         .to_not_found_response(errors::ApiErrorResponse::MerchantAccountNotFound)?;
@@ -485,7 +491,7 @@ pub async fn create_payment_connector(
     };
 
     // Validate Merchant api details and return error if not in correct format
-    let _: types::ConnectorAuthType = req
+    let auth: types::ConnectorAuthType = req
         .connector_account_details
         .clone()
         .parse_value("ConnectorAuthType")
@@ -494,6 +500,14 @@ pub async fn create_payment_connector(
             expected_format: "auth_type and api_key".to_string(),
         })?;
 
+    let conn_name =
+        ConnectorData::convert_connector(&state.conf.connectors, &req.connector_name.to_string())?;
+    conn_name.validate_auth_type(&auth).change_context(
+        errors::ApiErrorResponse::InvalidRequestData {
+            message: "The auth type is not supported for connector".to_string(),
+        },
+    )?;
+
     let frm_configs = get_frm_config_as_secret(req.frm_configs);
 
     let merchant_connector_account = domain::MerchantConnectorAccount {
@@ -538,7 +552,8 @@ pub async fn create_payment_connector(
         },
     };
 
-    let mca = store
+    let mca = state
+        .store
         .insert_merchant_connector_account(merchant_connector_account, &key_store)
         .await
         .to_duplicate_response(
diff --git a/crates/router/src/core/payments/operations/payment_session.rs b/crates/router/src/core/payments/operations/payment_session.rs
index ccfb3bfda19..7fa976b2d30 100644
--- a/crates/router/src/core/payments/operations/payment_session.rs
+++ b/crates/router/src/core/payments/operations/payment_session.rs
@@ -310,7 +310,6 @@ where
         payment_intent: &storage::payment_intent::PaymentIntent,
         key_store: &domain::MerchantKeyStore,
     ) -> RouterResult<api::ConnectorChoice> {
-        let connectors = &state.conf.connectors;
         let db = &state.store;
 
         let all_connector_accounts = db
@@ -390,13 +389,15 @@ where
             connector_and_supporting_payment_method_type
         {
             let connector_type = api::GetToken::from(payment_method_type);
-            if let Ok(connector_data) =
-                api::ConnectorData::get_connector_by_name(connectors, &connector, connector_type)
-                    .map_err(|err| {
-                        logger::error!(session_token_error=?err);
-                        err
-                    })
-            {
+            if let Ok(connector_data) = api::ConnectorData::get_connector_by_name(
+                &state.conf.connectors,
+                &connector,
+                connector_type,
+            )
+            .map_err(|err| {
+                logger::error!(session_token_error=?err);
+                err
+            }) {
                 session_connector_data.push(api::SessionConnectorData {
                     payment_method_type,
                     connector: connector_data,
diff --git a/crates/router/src/routes/admin.rs b/crates/router/src/routes/admin.rs
index dd8ca8d323c..8695e17a1b8 100644
--- a/crates/router/src/routes/admin.rs
+++ b/crates/router/src/routes/admin.rs
@@ -180,7 +180,7 @@ pub async fn payment_connector_create(
         state.get_ref(),
         &req,
         json_payload.into_inner(),
-        |state, _, req| create_payment_connector(&*state.store, req, &merchant_id),
+        |state, _, req| create_payment_connector(state, req, &merchant_id),
         &auth::AdminApiAuth,
     )
     .await
diff --git a/crates/router/src/types/api.rs b/crates/router/src/types/api.rs
index e8f4d497e6c..44e14c949ce 100644
--- a/crates/router/src/types/api.rs
+++ b/crates/router/src/types/api.rs
@@ -65,6 +65,11 @@ pub trait ConnectorCommon {
         "application/json"
     }
 
+    fn validate_auth_type(
+        &self,
+        val: &types::ConnectorAuthType,
+    ) -> Result<(), error_stack::Report<errors::ConnectorError>>;
+
     // FIXME write doc - think about this
     // fn headers(&self) -> Vec<(&str, &str)>;
 
@@ -266,7 +271,7 @@ impl ConnectorData {
         })
     }
 
-    fn convert_connector(
+    pub fn convert_connector(
         _connectors: &Connectors,
         connector_name: &str,
     ) -> CustomResult<BoxedConnector, errors::ApiErrorResponse> {

## Type of Change
<!-- Put an `x` in the boxes that apply -->

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

## Description

Issue is caused when in any Connector 's `auth_type`  we configure the invalid `auth_type`  for that particular connector and gets stored in the Db. Thus , whenever we call the Connector Integration we get a 500.


### Additional Changes

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

<!--
Provide links to the files with corresponding changes.

Following are the paths where you can find config files:
1. `config`
2. `crates/router/src/configs`
3. `loadtest/config`
-->




## How did you test it?

<img width="1728" alt="Screenshot 2023-07-25 at 5 33 44 PM" src="https://github.com/juspay/hyperswitch/assets/55580080/0f00aa25-071d-47d3-a826-da28d22cf400">

For the wrong `connector_auth_type`


<img width="1728" alt="Screenshot 2023-07-25 at 5 57 06 PM" src="https://github.com/juspay/hyperswitch/assets/55580080/43af662c-1319-4f2d-aa78-21bd857ea5aa">

For the correct `connector_auth_type`

## Checklist
<!-- Put an `x` in the boxes that apply -->

- [x] I formatted the code `cargo +nightly fmt --all`
- [x] I addressed lints thrown by `cargo clippy`
- [ ] I reviewed submitted code
- [ ] I added unit tests for my changes where possible
- [ ] I added a [CHANGELOG](/CHANGELOG.md) entry if applicable
