Skip to content

Commit 6d2ce11

Browse files
committed
Implemented Refresh Token
1 parent 92f2227 commit 6d2ce11

File tree

3 files changed

+55
-17
lines changed

3 files changed

+55
-17
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
# Aspose.Pdf for Cloud
2-
[Aspose.Pdf for Cloud](https://products.aspose.cloud/pdf/cloud) is a true REST API that enables you to perform a wide range of document processing operations including creation, manipulation, conversion and rendering of Pdf documents in the cloud.
1+
# Aspose.PDF Cloud
2+
[Aspose.PDF Cloud](https://products.aspose.cloud/pdf/cloud) is a true REST API that enables you to perform a wide range of document processing operations including creation, manipulation, conversion and rendering of Pdf documents in the cloud.
33

4-
Our Cloud SDKs are wrappers around REST API in various programming languages, allowing you to process documents in language of your choice quickly and easily, gaining all benefits of strong types and IDE highlights. This repository contains new generation SDKs for Aspose.Pdf for Cloud and examples.
4+
Our Cloud SDKs are wrappers around REST API in various programming languages, allowing you to process documents in language of your choice quickly and easily, gaining all benefits of strong types and IDE highlights. This repository contains new generation SDKs for Aspose.PDF Cloud and examples.
55

66
These SDKs are now fully supported. If you have any questions, see any bugs or have enhancement request, feel free to reach out to us at [Free Support Forums](https://forum.aspose.cloud/c/pdf).
77

@@ -41,7 +41,7 @@ class SdkUsage(object):
4141
Aspose PDF SDK includes a suite of unit tests within the "test" subdirectory. These Unit Tests also serves as examples of how to use the Aspose PDF SDK.
4242

4343
## Licensing
44-
All Aspose.Pdf for Cloud SDKs are licensed under [MIT License](LICENSE).
44+
All Aspose.PDF Cloud SDKs are licensed under [MIT License](LICENSE).
4545

4646
## Resources
4747
+ [**Website**](https://www.aspose.cloud)

asposepdfcloud/api_client.py

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import threading
3737

3838
from datetime import date, datetime
39+
from asposepdfcloud.models.http_status_code import HttpStatusCode
3940

4041
# python 2 and python 3 compatibility library
4142
from six import PY3, integer_types, iteritems, text_type
@@ -185,13 +186,24 @@ def __call_api(self, resource_path, method,
185186
self.__add_o_auth_token(header_params)
186187

187188

188-
# perform request and return response
189-
response_data = self.request(method, url,
190-
query_params=query_params,
191-
headers=header_params,
192-
post_params=post_params, body=body,
193-
_preload_content=_preload_content,
194-
_request_timeout=_request_timeout)
189+
try:
190+
# perform request and return response
191+
response_data = self.request(method, url,
192+
query_params=query_params,
193+
headers=header_params,
194+
post_params=post_params, body=body,
195+
_preload_content=_preload_content,
196+
_request_timeout=_request_timeout)
197+
except ApiException as error:
198+
if error.status == HttpStatusCode.UNAUTHORIZED:
199+
self.__refresh_token()
200+
self.__add_o_auth_token(header_params)
201+
response_data = self.request(method, url,
202+
query_params=query_params,
203+
headers=header_params,
204+
post_params=post_params, body=body,
205+
_preload_content=_preload_content,
206+
_request_timeout=_request_timeout)
195207

196208
self.last_response = response_data
197209

@@ -242,7 +254,36 @@ def __request_token(self):
242254

243255
data = json.loads(str(response_data.data))
244256
config.access_token = data['access_token']
257+
config.refresh_token = data['refresh_token']
258+
259+
def __refresh_token(self):
260+
config = Configuration()
261+
262+
# header parameters
263+
header_params = {"Content-Type" : "application/x-www-form-urlencoded"}
264+
265+
method = 'POST'
266+
267+
# post params
268+
post_params = {
269+
"grant_type" : "refresh_token",
270+
"refresh_token" : config.refresh_token
271+
}
272+
273+
# resource path
274+
resource_path = "/oauth2/token"
275+
276+
# request url
277+
url = self.host.replace("/v1.1", "") + resource_path
278+
279+
# perform request and return response
280+
response_data = self.request(method, url,
281+
headers=header_params,
282+
post_params=post_params)
245283

284+
data = json.loads(str(response_data.data))
285+
config.access_token = data['access_token']
286+
config.refresh_token = data['refresh_token']
246287

247288
def __add_o_auth_token(self, header_params):
248289
config = Configuration()

asposepdfcloud/configuration.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,13 @@ def __init__(self):
6767
self.api_client = None
6868
# Temp file folder for downloading files
6969
self.temp_folder_path = None
70-
71-
# Authentication Settings
72-
# App Key
73-
self.app_key = ""
74-
# App Key
75-
self.app_sid = ""
7670

7771
# access token for OAuth
7872
self.access_token = ""
7973

74+
# refresh token for OAuth
75+
self.refresh_token = ""
76+
8077
# Logging Settings
8178
self.logger = {}
8279
self.logger["package_logger"] = logging.getLogger("swagger_client")

0 commit comments

Comments
 (0)