From 8c1fb0713f5d2825c7f377a205e56b21b6deb55b Mon Sep 17 00:00:00 2001 From: Marcus Hof <13001502+MarconLP@users.noreply.github.com> Date: Mon, 4 Nov 2024 16:57:50 +0100 Subject: [PATCH] fix(cdp): update authentication to use the basic header (#25970) --- .../cdp/templates/mailjet/template_mailjet.py | 16 +++++++++++++--- .../templates/mailjet/test_template_mailjet.py | 6 +++--- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/posthog/cdp/templates/mailjet/template_mailjet.py b/posthog/cdp/templates/mailjet/template_mailjet.py index e0fa8863d0a0e..fb8fd7dfe42d9 100644 --- a/posthog/cdp/templates/mailjet/template_mailjet.py +++ b/posthog/cdp/templates/mailjet/template_mailjet.py @@ -10,6 +10,13 @@ "secret": True, "required": True, } +input_secret_key = { + "key": "secret_key", + "type": "string", + "label": "Mailjet Secret Key", + "secret": True, + "required": True, +} input_email = { "key": "email", "type": "string", @@ -43,7 +50,7 @@ fetch(f'https://api.mailjet.com/v3/REST/contact/', { 'method': 'POST', 'headers': { - 'Authorization': f'Bearer {inputs.api_key}', + 'Authorization': f'Basic {base64Encode(f'{inputs.api_key}:{inputs.secret_key}')}', 'Content-Type': 'application/json' }, 'body': { @@ -55,6 +62,7 @@ """.strip(), inputs_schema=[ input_api_key, + input_secret_key, input_email, { "key": "name", @@ -95,7 +103,7 @@ fetch(f'https://api.mailjet.com/v3/REST/contact/{inputs.email}/managecontactlists', { 'method': 'POST', 'headers': { - 'Authorization': f'Bearer {inputs.api_key}', + 'Authorization': f'Basic {base64Encode(f'{inputs.api_key}:{inputs.secret_key}')}', 'Content-Type': 'application/json' }, 'body': { @@ -110,6 +118,7 @@ """.strip(), inputs_schema=[ input_api_key, + input_secret_key, input_email, { "key": "contact_list_id", @@ -163,7 +172,7 @@ fetch(f'https://api.mailjet.com/v3.1/send', { 'method': 'POST', 'headers': { - 'Authorization': f'Bearer {inputs.api_key}', + 'Authorization': f'Basic {base64Encode(f'{inputs.api_key}:{inputs.secret_key}')}', 'Content-Type': 'application/json' }, 'body': { @@ -191,6 +200,7 @@ """.strip(), inputs_schema=[ input_api_key, + input_secret_key, { "key": "from_email", "type": "string", diff --git a/posthog/cdp/templates/mailjet/test_template_mailjet.py b/posthog/cdp/templates/mailjet/test_template_mailjet.py index 0163975411651..d4113367e1c6e 100644 --- a/posthog/cdp/templates/mailjet/test_template_mailjet.py +++ b/posthog/cdp/templates/mailjet/test_template_mailjet.py @@ -4,7 +4,7 @@ def create_inputs(**kwargs): - inputs = {"api_key": "API_KEY", "email": "example@posthog.com"} + inputs = {"api_key": "API_KEY", "secret_key": "SECRET_KEY", "email": "example@posthog.com"} inputs.update(kwargs) return inputs @@ -20,7 +20,7 @@ def test_function_works(self): "https://api.mailjet.com/v3/REST/contact/", { "method": "POST", - "headers": {"Authorization": "Bearer API_KEY", "Content-Type": "application/json"}, + "headers": {"Authorization": "Basic QVBJX0tFWTpTRUNSRVRfS0VZ", "Content-Type": "application/json"}, "body": {"Email": "example@posthog.com", "Name": "Example", "IsExcludedFromCampaigns": False}, }, ) @@ -43,7 +43,7 @@ def test_function_works(self): "https://api.mailjet.com/v3/REST/contact/example@posthog.com/managecontactlists", { "method": "POST", - "headers": {"Authorization": "Bearer API_KEY", "Content-Type": "application/json"}, + "headers": {"Authorization": "Basic QVBJX0tFWTpTRUNSRVRfS0VZ", "Content-Type": "application/json"}, "body": {"ContactsLists": [{"Action": "addnoforce", "ListID": 123}]}, }, )