@@ -48,7 +48,7 @@ class AuthenticationClient(BaseClient):
4848 **Documentation**: https://forge.autodesk.com/en/docs/oauth/v2/reference/http
4949 """
5050
51- def __init__ (self , base_url = BASE_URL ):
51+ def __init__ (self , base_url : str = BASE_URL ):
5252 """
5353 Create new instance of the client.
5454
@@ -57,7 +57,7 @@ def __init__(self, base_url=BASE_URL):
5757 """
5858 BaseClient .__init__ (self , base_url )
5959
60- def authenticate (self , client_id , client_secret , scopes ) :
60+ def authenticate (self , client_id : str , client_secret : str , scopes : list [ Scope ]) -> dict :
6161 """
6262 Generate a two-legged access token for specific set of scopes.
6363
@@ -88,7 +88,7 @@ def authenticate(self, client_id, client_secret, scopes):
8888 }
8989 return self ._post ('/authenticate' , form = form ).json ()
9090
91- def get_authorization_url (self , client_id , response_type , redirect_uri , scopes , state = None ):
91+ def get_authorization_url (self , client_id : str , response_type : str , redirect_uri : str , scopes : list [ Scope ] , state : str = None ) -> str :
9292 """
9393 Generate a URL to redirect an end user to in order to acquire the user’s consent
9494 for your app to access the specified resources.
@@ -122,7 +122,7 @@ def get_authorization_url(self, client_id, response_type, redirect_uri, scopes,
122122 url += '&state={}' .format (quote (state ))
123123 return url
124124
125- def get_token (self , client_id , client_secret , code , redirect_uri ) :
125+ def get_token (self , client_id : str , client_secret : str , code : str , redirect_uri : str ) -> dict :
126126 """
127127 Exchange an authorization code extracted from `get_authorization_url` callback for a three-legged access token.
128128 This API will only be used when the 'Authorization Code' grant type is being adopted.
@@ -159,7 +159,7 @@ def get_token(self, client_id, client_secret, code, redirect_uri):
159159 }
160160 return self ._post ('/gettoken' , form = form ).json ()
161161
162- def refresh_token (self , client_id , client_secret , refresh_token , scopes ) :
162+ def refresh_token (self , client_id : str , client_secret : str , refresh_token : str , scopes : list [ Scope ]) -> dict :
163163 """
164164 Acquire a new access token by using the refresh token provided by `get_token`.
165165
@@ -193,7 +193,7 @@ def refresh_token(self, client_id, client_secret, refresh_token, scopes):
193193 }
194194 return self ._post ('/refreshtoken' , form = form ).json ()
195195
196- def get_user_profile (self , access_token ) :
196+ def get_user_profile (self , access_token : str ) -> dict :
197197 """
198198 Get the profile information of an authorizing end user in a three-legged context.
199199
@@ -217,7 +217,7 @@ def get_user_profile(self, access_token):
217217 return self ._get ('/users/@me' , headers = headers ).json ()
218218
219219class TokenProviderInterface :
220- def get_token (self , scopes ) :
220+ def get_token (self , scopes : list [ Scope ]) -> str :
221221 """
222222 Generates access token for given set of scopes.
223223
@@ -235,7 +235,7 @@ class SimpleTokenProvider(TokenProviderInterface):
235235 When using this approach, make sure that the hard-coded access token supports all the scopes that may be needed.
236236 """
237237
238- def __init__ (self , access_token ):
238+ def __init__ (self , access_token : str ):
239239 """
240240 Create new instance of the provider.
241241
@@ -244,15 +244,15 @@ def __init__(self, access_token):
244244 """
245245 self .access_token = access_token
246246
247- def get_token (self , scopes ) :
247+ def get_token (self , scopes : list [ Scope ]) -> str :
248248 return self .access_token
249249
250250class OAuthTokenProvider (TokenProviderInterface ):
251251 """
252252 Helper class that automatically generates (and caches) access tokens using specific app credentials.
253253 """
254254
255- def __init__ (self , client_id , client_secret ):
255+ def __init__ (self , client_id : str , client_secret : str ):
256256 """
257257 Create new instance of the provider.
258258
@@ -265,7 +265,7 @@ def __init__(self, client_id, client_secret):
265265 self .auth_client = AuthenticationClient ()
266266 self .cache = {}
267267
268- def get_token (self , scopes ) :
268+ def get_token (self , scopes : list [ Scope ]) -> str :
269269 cache_key = '+' .join (map (lambda s : s .value , scopes ))
270270 now = datetime .now ()
271271 if cache_key in self .cache :
@@ -277,7 +277,7 @@ def get_token(self, scopes):
277277 return auth
278278
279279class BaseOAuthClient (BaseClient ):
280- def __init__ (self , token_provider , base_url ):
280+ def __init__ (self , token_provider : TokenProviderInterface , base_url : str ):
281281 """
282282 Create new instance of the client.
283283
@@ -288,31 +288,31 @@ def __init__(self, token_provider, base_url):
288288 BaseClient .__init__ (self , base_url )
289289 self .token_provider = token_provider
290290
291- def _get (self , url , scopes , params = None , headers = None ):
291+ def _get (self , url : str , scopes : list [ Scope ] , params : dict = None , headers : dict = None ):
292292 if not headers :
293293 headers = {}
294294 self ._set_auth_headers (headers , scopes )
295295 return BaseClient ._get (self , url , params , headers )
296296
297- def _post (self , url , scopes , form = None , json = None , buff = None , params = None , headers = None ):
297+ def _post (self , url : str , scopes : list [ Scope ] , form : dict = None , json : dict = None , buff = None , params : dict = None , headers : dict = None ):
298298 if not headers :
299299 headers = {}
300300 self ._set_auth_headers (headers , scopes )
301301 return BaseClient ._post (self , url , form , json , buff , params , headers )
302302
303- def _put (self , url , scopes , form = None , json = None , buff = None , params = None , headers = None ):
303+ def _put (self , url : str , scopes : list [ Scope ] , form : dict = None , json : dict = None , buff = None , params : dict = None , headers : dict = None ):
304304 if not headers :
305305 headers = {}
306306 self ._set_auth_headers (headers , scopes )
307307 return BaseClient ._put (self , url , form , json , buff , params , headers )
308308
309- def _delete (self , url , scopes , params = None , headers = None ):
309+ def _delete (self , url : str , scopes : list [ Scope ] , params : dict = None , headers : dict = None ):
310310 if not headers :
311311 headers = {}
312312 self ._set_auth_headers (headers , scopes )
313313 return BaseClient ._delete (self , url , params , headers )
314314
315- def _set_auth_headers (self , headers , scopes ):
315+ def _set_auth_headers (self , headers : dict , scopes : list [ Scope ] ):
316316 if not 'Authorization' in headers :
317317 auth = self .token_provider .get_token (scopes )
318318 headers ['Authorization' ] = 'Bearer {}' .format (auth ['access_token' ])
0 commit comments