35
35
from webexteamssdk .utils import check_type
36
36
from .access_tokens import AccessTokensAPI
37
37
from .events import EventsAPI
38
+ from .guest_issuer import GuestIssuerAPI
38
39
from .licenses import LicensesAPI
39
40
from .memberships import MembershipsAPI
40
41
from .messages import MessagesAPI
45
46
from .team_memberships import TeamMembershipsAPI
46
47
from .teams import TeamsAPI
47
48
from .webhooks import WebhooksAPI
48
- from .guest_issuer import GuestIssuerAPI
49
49
50
50
51
51
class WebexTeamsAPI (object ):
@@ -62,18 +62,26 @@ class WebexTeamsAPI(object):
62
62
def __init__ (self , access_token = None , base_url = DEFAULT_BASE_URL ,
63
63
single_request_timeout = DEFAULT_SINGLE_REQUEST_TIMEOUT ,
64
64
wait_on_rate_limit = DEFAULT_WAIT_ON_RATE_LIMIT ,
65
- object_factory = immutable_data_factory ):
65
+ object_factory = immutable_data_factory ,
66
+ client_id = None ,
67
+ client_secret = None ,
68
+ oauth_code = None ,
69
+ redirect_uri = None ):
66
70
"""Create a new WebexTeamsAPI object.
67
71
68
72
An access token must be used when interacting with the Webex Teams API.
69
- This package supports two methods for you to provide that access token:
73
+ This package supports three methods for you to provide that access
74
+ token:
70
75
71
76
1. You may manually specify the access token via the `access_token`
72
77
argument, when creating a new WebexTeamsAPI object.
73
78
74
79
2. If an access_token argument is not supplied, the package checks
75
80
for a WEBEX_TEAMS_ACCESS_TOKEN environment variable.
76
81
82
+ 3. Provide the parameters (client_id, client_secret, oauth_code and
83
+ oauth_redirect_uri) from your oauth flow.
84
+
77
85
An AccessTokenError is raised if an access token is not provided
78
86
via one of these two methods.
79
87
@@ -92,6 +100,14 @@ def __init__(self, access_token=None, base_url=DEFAULT_BASE_URL,
92
100
webexteamssdk.config.DEFAULT_WAIT_ON_RATE_LIMIT.
93
101
object_factory(callable): The factory function to use to create
94
102
Python objects from the returned Webex Teams JSON data objects.
103
+ client_id(basestring): The client id of your integration. Provided
104
+ upon creation in the portal.
105
+ client_secret(basestring): The client secret of your integration.
106
+ Provided upon creation in the portal.
107
+ oauth_code(basestring): The oauth authorization code provided by
108
+ the user oauth process.
109
+ oauth_redirect_uri(basestring): The redirect URI used in the user
110
+ OAuth process.
95
111
96
112
Returns:
97
113
WebexTeamsAPI: A new WebexTeamsAPI object.
@@ -106,8 +122,31 @@ def __init__(self, access_token=None, base_url=DEFAULT_BASE_URL,
106
122
check_type (base_url , basestring )
107
123
check_type (single_request_timeout , int )
108
124
check_type (wait_on_rate_limit , bool )
125
+ check_type (client_id , basestring , may_be_none = True )
126
+ check_type (client_secret , basestring , may_be_none = True )
127
+ check_type (oauth_code , basestring , may_be_none = True )
128
+ check_type (redirect_uri , basestring , may_be_none = True )
109
129
110
130
access_token = access_token or WEBEX_TEAMS_ACCESS_TOKEN
131
+
132
+ # Init AccessTokensAPI wrapper early to use for oauth requests
133
+ self .access_tokens = AccessTokensAPI (
134
+ base_url , object_factory ,
135
+ single_request_timeout = single_request_timeout ,
136
+ )
137
+
138
+ # Check if the user has provided the required oauth parameters
139
+ oauth_param_list = [client_id , client_secret , oauth_code , redirect_uri ]
140
+ if not access_token and all (oauth_param_list ):
141
+ access_token = self .access_tokens .get (
142
+ client_id = client_id ,
143
+ client_secret = client_secret ,
144
+ code = oauth_code ,
145
+ redirect_uri = redirect_uri
146
+ ).access_token
147
+
148
+ # If an access token hasn't been provided as a parameter, environment
149
+ # variable, or obtained via an OAuth exchange raise an error.
111
150
if not access_token :
112
151
raise AccessTokenError (
113
152
"You must provide a Webex Teams access token to interact with "
@@ -139,10 +178,6 @@ def __init__(self, access_token=None, base_url=DEFAULT_BASE_URL,
139
178
self .organizations = OrganizationsAPI (self ._session , object_factory )
140
179
self .licenses = LicensesAPI (self ._session , object_factory )
141
180
self .roles = RolesAPI (self ._session , object_factory )
142
- self .access_tokens = AccessTokensAPI (
143
- self .base_url , object_factory ,
144
- single_request_timeout = single_request_timeout
145
- )
146
181
self .events = EventsAPI (self ._session , object_factory )
147
182
self .guest_issuer = GuestIssuerAPI (self ._session , object_factory )
148
183
0 commit comments