Skip to content

Commit

Permalink
feat(hooks): make signing secret optional (#23)
Browse files Browse the repository at this point in the history
* fix: make signing secret optional

Make signing secret optional in cases where we only need to authenticate a user

* Update README.md
  • Loading branch information
jackton1 authored Aug 27, 2024
1 parent c6e5b9d commit 9a78bde
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ Initialise a new Terra instance with:
```py
from terra.base_client import Terra

# For user authentication
terra = Terra(api_key='YOUR API KEY', dev_id='YOUR DEV ID');

# For web hook endpoints
terra = Terra(api_key='YOUR API KEY', dev_id='YOUR DEV ID', secret='YOUR TERRA SECRET');
```

Expand Down
7 changes: 5 additions & 2 deletions terra/base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ class Terra:
Args:
api_key (:obj:`str`) : Your API Key
dev_id (:obj:`str`) : Your dev ID
secret (:obj:`str`) : Your terra secret (for web hooks)
secret (:obj:`str`, optional): Your terra secret (for web hooks). Defaults to None.
"""

def __init__(self, api_key: str, dev_id: str, secret: str) -> None:
def __init__(self, api_key: str, dev_id: str, secret: typing.Optional[str] = None) -> None:
self.api_key = api_key
self.dev_id = dev_id
self.secret = secret
Expand Down Expand Up @@ -480,6 +480,9 @@ def check_terra_signature(self, body: str, header: str) -> bool:
Returns:
:obj:`bool`: True if the API response comes from Terra
"""
if self.secret is None:
raise ValueError("A valid 'secret' is required for web hooks. Please provide your Terra secret.")


t, sig = (pair.split("=")[-1] for pair in header.split(","))

Expand Down

0 comments on commit 9a78bde

Please sign in to comment.