From 5fd912f5fe1044c8c06987c26c6d8c23b36b5cd6 Mon Sep 17 00:00:00 2001 From: Chris Caron Date: Sun, 5 May 2024 12:42:08 -0400 Subject: [PATCH] clicksend:// authentication bugfix (#1121) --- apprise/plugins/clicksend.py | 21 ++++++++++++++------- test/test_plugin_clicksend.py | 4 ++++ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/apprise/plugins/clicksend.py b/apprise/plugins/clicksend.py index 0c1f533f..9ade1055 100644 --- a/apprise/plugins/clicksend.py +++ b/apprise/plugins/clicksend.py @@ -41,7 +41,6 @@ # import requests from json import dumps -from base64 import b64encode from .base import NotifyBase from ..url import PrivacyMode @@ -89,7 +88,7 @@ class NotifyClickSend(NotifyBase): # Define object templates templates = ( - '{schema}://{user}:{password}@{targets}', + '{schema}://{user}:{apikey}@{targets}', ) # Define our template tokens @@ -99,11 +98,12 @@ class NotifyClickSend(NotifyBase): 'type': 'string', 'required': True, }, - 'password': { - 'name': _('Password'), + 'apikey': { + 'name': _('API Key'), 'type': 'string', 'private': True, 'required': True, + 'map_to': 'password', }, 'target_phone': { 'name': _('Target Phone No'), @@ -124,6 +124,9 @@ class NotifyClickSend(NotifyBase): 'to': { 'alias_of': 'targets', }, + 'key': { + 'alias_of': 'apikey', + }, 'batch': { 'name': _('Batch Mode'), 'type': 'bool', @@ -174,9 +177,6 @@ class NotifyClickSend(NotifyBase): headers = { 'User-Agent': self.app_id, 'Content-Type': 'application/json; charset=utf-8', - 'Authorization': 'Basic {}'.format( - b64encode('{}:{}'.format( - self.user, self.password).encode('utf-8'))), } # error tracking (used for function return) @@ -208,6 +208,7 @@ class NotifyClickSend(NotifyBase): r = requests.post( self.notify_url, data=dumps(payload), + auth=(self.user, self.password), headers=headers, verify=self.verify_certificate, timeout=self.request_timeout, @@ -322,6 +323,12 @@ class NotifyClickSend(NotifyBase): results['batch'] = \ parse_bool(results['qsd'].get('batch', False)) + # API Key + if 'key' in results['qsd'] and len(results['qsd']['key']): + # Extract the API Key from an argument + results['password'] = \ + NotifyClickSend.unquote(results['qsd']['key']) + # Support the 'to' variable so that we can support rooms this way too # The 'to' makes it easier to use yaml configuration if 'to' in results['qsd'] and len(results['qsd']['to']): diff --git a/test/test_plugin_clicksend.py b/test/test_plugin_clicksend.py index 3a0fab72..697a5801 100644 --- a/test/test_plugin_clicksend.py +++ b/test/test_plugin_clicksend.py @@ -62,6 +62,10 @@ apprise_url_tests = ( # valid number - no batch 'instance': NotifyClickSend, }), + ('clicksend://user@{}?batch=no&key=abc123'.format('3' * 14), { + # valid number - no batch + 'instance': NotifyClickSend, + }), ('clicksend://user:pass@{}'.format('3' * 14), { 'instance': NotifyClickSend, # throw a bizzare code forcing us to fail to look it up