From 0399fef1b83599502acbf45ef483242bae69c2fb Mon Sep 17 00:00:00 2001 From: Chris Lunsford Date: Thu, 9 Jul 2020 16:22:40 -0400 Subject: [PATCH 1/2] Update WebexTeamsAPI Provide access to the access_tokens API wrapper directly from the WebexTeamsAPI class *before* instantiating an instance of the class (which requires an access token). Also provide convenience class methods that will instantiate a new WebexTeamsAPI connection object from an OAuth Authorization Code or Refresh Token. --- webexteamssdk/api/__init__.py | 63 +++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/webexteamssdk/api/__init__.py b/webexteamssdk/api/__init__.py index e742e0a..29da0aa 100644 --- a/webexteamssdk/api/__init__.py +++ b/webexteamssdk/api/__init__.py @@ -230,3 +230,66 @@ def single_request_timeout(self): def wait_on_rate_limit(self): """Automatic rate-limit handling enabled / disabled.""" return self._session.wait_on_rate_limit + + # Create a class attribute for the Access Tokens API that can be accessed + # before WebexTeamsAPI object is initialized. + access_tokens = AccessTokensAPI( + base_url=DEFAULT_BASE_URL, + object_factory=immutable_data_factory, + single_request_timeout=DEFAULT_SINGLE_REQUEST_TIMEOUT, + ) + + @classmethod + def from_oauth_code(cls, client_id, client_secret, code, redirect_uri): + """Create a new WebexTeamsAPI connection object using an OAuth code. + + Exchange an Authorization Code for an Access Token, then use the access + token to create a new WebexTeamsAPI connection object. + + Args: + client_id(basestring): Provided when you created your integration. + client_secret(basestring): Provided when you created your + integration. + code(basestring): The Authorization Code provided by the user + OAuth process. + redirect_uri(basestring): The redirect URI used in the user OAuth + process. + + Returns: + AccessToken: An AccessToken object with the access token provided + by the Webex Teams cloud. + + Raises: + TypeError: If the parameter types are incorrect. + ApiError: If the Webex Teams cloud returns an error. + """ + token_obj = cls.access_tokens.get(client_id, client_secret, code, + redirect_uri) + + return cls(access_token=token_obj.access_token) + + @classmethod + def from_oauth_refresh(cls, client_id, client_secret, refresh_token): + """Create a new WebexTeamsAPI connection object using an OAuth refresh. + + Exchange a refresh token for an Access Token, then use the access + token to create a new WebexTeamsAPI connection object. + + Args: + client_id(basestring): Provided when you created your integration. + client_secret(basestring): Provided when you created your + integration. + refresh_token(basestring): Provided when you requested the Access + Token. + + Returns: + AccessToken: With the access token provided by the Webex Teams + cloud. + + Raises: + TypeError: If the parameter types are incorrect. + ApiError: If the Webex Teams cloud returns an error. + """ + token_obj = cls.access_tokens.refresh(client_id, client_secret, + refresh_token) + return cls(access_token=token_obj.access_token) From c316906c727edcf621b03d04b4cab9ac9103cbdf Mon Sep 17 00:00:00 2001 From: Chris Lunsford Date: Thu, 9 Jul 2020 16:54:07 -0400 Subject: [PATCH 2/2] Update docstrings --- webexteamssdk/api/__init__.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/webexteamssdk/api/__init__.py b/webexteamssdk/api/__init__.py index 29da0aa..de1ab94 100644 --- a/webexteamssdk/api/__init__.py +++ b/webexteamssdk/api/__init__.py @@ -256,8 +256,8 @@ def from_oauth_code(cls, client_id, client_secret, code, redirect_uri): process. Returns: - AccessToken: An AccessToken object with the access token provided - by the Webex Teams cloud. + WebexTeamsAPI: A new WebexTeamsAPI object initialized with the + access token from the OAuth Authentication Code exchange. Raises: TypeError: If the parameter types are incorrect. @@ -283,8 +283,8 @@ def from_oauth_refresh(cls, client_id, client_secret, refresh_token): Token. Returns: - AccessToken: With the access token provided by the Webex Teams - cloud. + WebexTeamsAPI: A new WebexTeamsAPI object initialized with the + access token from the OAuth Refresh Token exchange. Raises: TypeError: If the parameter types are incorrect.