Skip to content

Commit

Permalink
twilio python changes for orgs api uptake
Browse files Browse the repository at this point in the history
  • Loading branch information
AsabuHere committed Sep 27, 2024
1 parent 0211f23 commit 27dec32
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 5 additions & 1 deletion twilio/authStrategy/tokenAuthStrategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,23 @@ def __init__(self, token_manager: TokenManager):
self.lock = threading.Lock()

def get_auth_string(self) -> str:
if self.token is None:
self.fetch_token()
return f"Bearer {self.token}"

def requires_authentication(self) -> bool:
return True

def fetch_token(self):
print(f'token is fetch_token {self.token}')
if self.token is None or self.token == "" or self.is_token_expired(self.token):
with self.lock:
if self.token is None or self.token == "" or self.is_token_expired(self.token):
self.token = self.token_manager.fetch_access_token()

def is_token_expired(self, token):
decoded_jwt = jwt.decode(token, options={"verify_signature": True})
print(f'token is {token}')
decoded_jwt = jwt.decode(token, options={"verify_signature": True}, algorithms=["RS256"])
expires_at = decoded_jwt.get("exp")
# Add a buffer of 30 seconds
buffer_seconds = 30
Expand Down
4 changes: 1 addition & 3 deletions twilio/base/client_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,7 @@ def request(
auth_strategy = None ##Initialization
if self.credential_provider:
auth_strategy = self.credential_provider.to_auth_strategy()
if auth_strategy.auth_type == AuthType.TOKEN:
auth_strategy.fetch_token()
headers["Authorization"] = auth_strategy.get_auth_string()
headers["Authorization"] = auth_strategy.get_auth_string()
else:
auth = self.get_auth(auth)

Expand Down

0 comments on commit 27dec32

Please sign in to comment.