Skip to content

Patch Release 1.0.1: Remove hardcoded x-api-key header and instead use client id from credentials used to create the access token. #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def parse_requirements(filename, session=None):

setuptools.setup(
name="pdfservices-sdk",
version="1.0.0",
version="1.0.1",
author='Adobe Document Services',
author_email='Adobe',
license='Apache2',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@ def session_token(self):
@abstractmethod
def refresh_token(self):
pass

@abstractmethod
def get_api_key(self):
pass
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def older_in_minute(self):
return int((datetime.now() - self.token.expired_at).seconds / 60)

def refresh_token(self):
jwt_token = self.prepare_jwt()
jwt_token = self._prepare_jwt()
url = "{jwt_endpoint}/{jwt_uri_suffix}".format(
jwt_endpoint=self.service_account_configuration.ims_base_uri,
jwt_uri_suffix=ServiceConstants.JWT_URI_SUFFIX
Expand All @@ -67,6 +67,9 @@ def refresh_token(self):
raise SdkException("Exception in fetching access token", sys.exc_info())
return self.token

def get_api_key(self):
return self.service_account_configuration.client_id

def handle_ims_failure(self, response):
self._logger.error(
"IMS call failed with status code {error_code}".format(error_code=response.status_code))
Expand All @@ -86,7 +89,7 @@ def handle_ims_failure(self, response):
error_message=content.get("error_description", None),
request_tracking_id=ResponseUtil.get_request_tracking_id_from_response(response, True))

def prepare_jwt(self):
def _prepare_jwt(self):
audience = "{base_uri}/{audience_suffix}{client_id}".format(
base_uri=self.service_account_configuration.ims_base_uri,
audience_suffix=ServiceConstants.JWT_AUDIENCE_SUFFIX,
Expand Down
5 changes: 2 additions & 3 deletions src/adobe/pdfservices/operation/internal/http/http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def process_request(http_request: HttpRequest, success_status_codes: List,
# get token and append auth header
access_token = http_request.authenticator.session_token().access_token
http_request.headers[DefaultHeaders.AUTHORIZATION_HEADER_NAME] = "Bearer " + access_token
http_request.headers[DefaultHeaders.X_API_KEY_HEADER_NAME] = http_request.authenticator.get_api_key()

# retry the request if it fails with 401 and specific error code
while (True):
Expand All @@ -51,9 +52,7 @@ def _append_default_headers(headers: dict):
# Set SDK Info header
headers[DefaultHeaders.DC_APP_INFO_HEADER_KEY] = "{lang}-{name}-{version}".format(lang="python",
name='pdfservices-sdk',
version='1.0.0')
# Set default API Key
headers[DefaultHeaders.X_API_KEY_HEADER_NAME] = DefaultHeaders.X_API_KEY_HEADER_VALUE
version='1.0.1')
headers[DefaultHeaders.ACCEPT_HEADER_NAME] = DefaultHeaders.JSON_TXT_CONTENT_TYPE


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,4 @@ class DefaultHeaders:
DC_APP_INFO_HEADER_KEY = "x-api-app-info"
X_DCSDK_OPS_INFO_HEADER_NAME = "x-dcsdk-ops-info"
SESSION_TOKEN_REQUEST_ID_HEADER_KEY = "X-DEBUG-ID"
X_API_KEY_HEADER_VALUE = "AdobeDCPlatformExtractKey"
JSON_TXT_CONTENT_TYPE = "application/json, text/plain, */*"