Skip to content

Commit

Permalink
Feat: service token v2 support (#174)
Browse files Browse the repository at this point in the history
* feat: removed header capitalization logic

* feat: updated token header construction

---------

Co-authored-by: Rohan Chaturvedi <[email protected]>
  • Loading branch information
nimish-ks and rohan-chaturvedi authored Oct 28, 2024
1 parent 82a7036 commit de919d2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion phase_cli/utils/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def construct_http_headers(token_type: str, app_token: str) -> Dict[str, str]:
Dict[str, str]: The common headers including User-Agent.
"""
return {
"Authorization": f"Bearer {token_type.capitalize()} {app_token}",
"Authorization": f"Bearer {token_type} {app_token}",
"User-Agent": get_user_agent()
}

Expand Down
11 changes: 8 additions & 3 deletions phase_cli/utils/phase_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,16 @@ def __init__(self, init=True, pss=None, host=None):
token_type = "service token" if "pss_service" in app_secret else "user token"
raise ValueError(f"Invalid Phase {token_type}")

# Storing the token type as a string for easier access
self._token_type = "service" if self.is_service_token else "user"

# Store token segments
pss_segments = app_secret.split(':')
self._app_secret = AppSecret(*pss_segments)

# If type service_token && version == 2; set token header as ServiceAccount
if self.is_service_token and self._app_secret.pes_version == "v2":
self._token_type = "ServiceAccount"
# Else decide between User token or legacy service token header
else:
self._token_type = "Service" if self.is_service_token else "User"


def _find_matching_environment_key(self, user_data, env_id):
Expand Down

0 comments on commit de919d2

Please sign in to comment.