1616import sys
1717import os
1818import re
19+ import six
1920
2021# python 2 and python 3 compatibility library
2122from six import iteritems
@@ -40,6 +41,57 @@ def __init__(self, api_client=None):
4041 config .api_client = ApiClient ()
4142 self .api_client = config .api_client
4243
44+ self .__request_token ()
45+
46+ def __request_token (self ):
47+ config = self .api_client .configuration
48+ host = config .host
49+ self .api_client .host = 'https://api.aspose.cloud/'
50+ request_url = "oauth2/token"
51+ form_params = [('grant_type' , 'client_credentials' ), ('client_id' , config .api_key ['app_sid' ]),
52+ ('client_secret' , config .api_key ['api_key' ])]
53+
54+ header_params = {'Accept' : 'application/json' , 'Content-Type' : 'application/x-www-form-urlencoded' }
55+
56+ data = self .api_client .call_api (request_url , 'POST' ,
57+ {},
58+ [],
59+ header_params ,
60+ post_params = form_params ,
61+ response_type = 'object' ,
62+ files = {}, _return_http_data_only = True )
63+ access_token = data ['access_token' ] if six .PY3 else data ['access_token' ].encode ('utf8' )
64+ refresh_token = data ['refresh_token' ] if six .PY3 else data ['refresh_token' ].encode ('utf8' )
65+ self .api_client .configuration .access_token = access_token
66+ self .api_client .host = host
67+ self .api_client .configuration .refresh_token = refresh_token
68+
69+ self .api_client .set_default_header ("Authorization" , "Bearer " + access_token )
70+
71+
72+ # Refresh token method is going to be removed soon. Obsolete, do not use
73+ def __refresh_token (self ):
74+ config = self .api_client .configuration
75+ host = config .host
76+ config .host = ''
77+ request_url = "oauth2/token"
78+ form_params = [('grant_type' , 'refresh_token' ), ('refresh_token' , config .refresh_token )]
79+
80+ header_params = {'Accept' : 'application/json' , 'Content-Type' : 'application/x-www-form-urlencoded' }
81+
82+ data = self .api_client .call_api (request_url , 'POST' ,
83+ {},
84+ [],
85+ header_params ,
86+ post_params = form_params ,
87+ response_type = 'object' ,
88+ files = {}, _return_http_data_only = True )
89+ access_token = data ['access_token' ] if six .PY3 else data ['access_token' ].encode ('utf8' )
90+ refresh_token = data ['refresh_token' ] if six .PY3 else data ['refresh_token' ].encode ('utf8' )
91+ self .api_client .configuration .access_token = access_token
92+ self .api_client .configuration .host = host
93+ self .api_client .configuration .refresh_token = refresh_token
94+
4395 def diagram_file_get_diagram (self , name , ** kwargs ):
4496 """
4597 Read document info or export.
@@ -511,3 +563,6 @@ def diagram_file_put_upload_with_http_info(self, name, **kwargs):
511563 _preload_content = params .get ('_preload_content' , True ),
512564 _request_timeout = params .get ('_request_timeout' ),
513565 collection_formats = collection_formats )
566+
567+
568+
0 commit comments