Skip to content

Commit 484cc86

Browse files
author
Ibrahim
authored
Merge pull request #8 from messagemedia/hmac
Added HMAC authentication
2 parents e772f59 + f511ffe commit 484cc86

File tree

6 files changed

+19
-20
lines changed

6 files changed

+19
-20
lines changed

examples/sms_check_replies.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55

66
auth_user_name = 'YOUR_API_KEY' # The username to use with basic authentication
77
auth_password = 'YOUR_API_SECRET' # The password to use with basic authentication
8+
use_hmac_authentication = False # Change to True if you are using HMAC keys
89

9-
client = MessageMediaMessagesClient(auth_user_name, auth_password)
10+
client = MessageMediaMessagesClient(auth_user_name, auth_password, use_hmac_authentication)
1011

1112
replies_client = client.replies
1213

examples/sms_delivery_reports.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55

66
auth_user_name = 'YOUR_API_KEY' # The username to use with basic authentication
77
auth_password = 'YOUR_API_SECRET' # The password to use with basic authentication
8+
use_hmac_authentication = False # Change to True if you are using HMAC keys
89

9-
client = MessageMediaMessagesClient(auth_user_name, auth_password)
10+
client = MessageMediaMessagesClient(auth_user_name, auth_password, use_hmac_authentication)
1011

1112
delivery_reports_client = client.delivery_reports
1213

examples/sms_send.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@
22
from message_media_messages.message_media_messages_client import MessageMediaMessagesClient
33
import json
44

5-
auth_user_name = 'YOUR_API_KEY' # The username to use with basic authentication
6-
auth_password = 'YOUR_API_SECRET' # The password to use with basic authentication
5+
auth_user_name = 'YOUR_API_KEY' # The username to use with basic/HMAC authentication
6+
auth_password = 'YOUR_API_SECRET' # The password to use with basic/HMAC authentication
7+
use_hmac_authentication = False # Change to True if you are using HMAC keys
78

8-
client = MessageMediaMessagesClient(auth_user_name, auth_password)
9+
client = MessageMediaMessagesClient(auth_user_name, auth_password, use_hmac_authentication)
910

1011
messages_client = client.messages
1112

1213
body_value = '''{
1314
"messages":[
1415
{
1516
"content":"My first message",
16-
"destination_number":"YOUR_MOBILE_NUMBER"
17+
"destination_number":"MOBILE_NUMBER"
1718
}
1819
]
1920
}'''

examples/sms_status.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@
33
import sys
44
import json
55

6-
auth_user_name = 'YOUR_API_KEY' # The username to use with basic authentication
7-
auth_password = 'YOUR_API_SECRET' # The password to use with basic authentication
6+
auth_user_name = 'YOUR_API_KEY' # The username to use with basic/HMAC authentication
7+
auth_password = 'YOUR_API_SECRET' # The password to use with basic/HMAC authentication
8+
use_hmac_authentication = False # Change to True if you are using HMAC keys
89

9-
client = MessageMediaMessagesClient(auth_user_name, auth_password)
10+
client = MessageMediaMessagesClient(auth_user_name, auth_password, use_hmac_authentication)
1011

11-
messages_client = client.messages
12+
delivery_reports_client = client.delivery_reports
1213

13-
message_id = 'messageId'
14-
15-
result = messages_client.get_message_status(message_id)
14+
result = delivery_reports_client.get_check_delivery_reports()

message_media_messages/http/auth/hmac_auth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def apply(http_request, url, body=None):
4141

4242
if body is not None:
4343
m = hashlib.md5()
44-
m.update(body)
44+
#m.update(body)
4545
content_hash = m.hexdigest()
4646
content_signature = "x-Content-MD5: {}\n".format(content_hash)
4747
content_header = "x-Content-MD5 "

message_media_messages/message_media_messages_client.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,11 @@ def replies(self):
3030
def __init__(self,
3131
auth_user_name=None,
3232
auth_password=None,
33-
use_hmac_autentication=False):
33+
use_hmac_authentication=False):
3434

35-
if use_hmac_autentication and auth_user_name is not None:
35+
if use_hmac_authentication:
3636
Configuration.hmac_auth_user_name = auth_user_name
37-
if use_hmac_autentication and auth_password is not None:
3837
Configuration.hmac_auth_password = auth_password
39-
40-
if auth_user_name is not None:
38+
else:
4139
Configuration.basic_auth_user_name = auth_user_name
42-
if auth_password is not None:
4340
Configuration.basic_auth_password = auth_password

0 commit comments

Comments
 (0)