Skip to content

Commit a5ac10f

Browse files
author
PureCloud Jenkins
committed
192.0.0
1 parent 36ba926 commit a5ac10f

File tree

293 files changed

+21330
-2799
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

293 files changed

+21330
-2799
lines changed

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,27 @@ apiclient, auth_token_info = apiclient.refresh_code_authorization_token(os.envir
9494
refresh_token)
9595
```
9696

97+
### PKCE Grant
98+
99+
* The app is authenticating as a human, the [PKCE Grant](https://developer.genesys.cloud/authorization/platform-auth/use-pkce)
100+
* The app is served via a web server
101+
* There is server-side code that will be making API requests
102+
103+
```python
104+
apiclient, auth_token_info = apiclient.get_pkce_token(os.environ['GENESYS_CLOUD_CODEAUTH_CLIENT_ID'],
105+
code_verifier,
106+
auth_code,
107+
"https://redirect-uri.com/oauth/callback")
108+
usersApi = PureCloudPlatformClientV2.UsersApi(apiclient)
109+
```
110+
111+
The SDK provides methods to generate a PKCE Code Verifier and to compute PKCE Code Challenge.
112+
113+
```python
114+
code_verifier = PureCloudPlatformClientV2.api_client.ApiClient().generate_pkce_code_verifier(128)
115+
code_challenge = PureCloudPlatformClientV2.api_client.ApiClient().compute_pkce_code_challenge(code_verifier)
116+
```
117+
97118
### Setting the Environment
98119

99120
If connecting to a Genesys Cloud environment other than mypurecloud.com (e.g. mypurecloud.ie), set the new base path before constructing any API classes. The new base path should be the base path to the Platform API for your environment.

build/.openapi-generator/FILES

Lines changed: 132 additions & 2 deletions
Large diffs are not rendered by default.

build/APIData.json

Lines changed: 2510 additions & 2244 deletions
Large diffs are not rendered by default.

build/PureCloudPlatformClientV2/__init__.py

Lines changed: 60 additions & 1 deletion
Large diffs are not rendered by default.

build/PureCloudPlatformClientV2/api_client.py

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
import base64
3636
import json
3737
import time
38+
import string
39+
import hashlib
3840

3941

4042
from datetime import datetime, timezone
@@ -243,6 +245,66 @@ def refresh_code_authorization_token(self,client_id,client_secret,refresh_token)
243245

244246
return self, data[0]
245247

248+
def generate_pkce_code_verifier(self,length):
249+
"""
250+
Generate a random string used as PKCE Code Verifier.
251+
"""
252+
if length < 43 or length > 128:
253+
raise ValueError('PKCE Code Verifier (length) must be between 43 and 128 characters')
254+
255+
# Get all the ASCII letters in lowercase and uppercase
256+
unreserved_characters = string.ascii_letters + string.digits + '-' + '.' + '_'
257+
# Randomly choose characters from unreserved_characters for the given length of the string
258+
random_string = ''.join(random.choice(unreserved_characters) for i in range(length))
259+
return random_string
260+
261+
def compute_pkce_code_challenge(self,code):
262+
"""
263+
Compute PKCE Code Challenge from Code Verifier.
264+
"""
265+
if len(code) < 43 or len(code) > 128:
266+
raise ValueError('PKCE Code Verifier (length) must be between 43 and 128 characters')
267+
268+
code_hash = hashlib.sha256(code.encode('ascii'))
269+
return (base64.urlsafe_b64encode(code_hash.digest()).decode('ascii')).split('=')[0]
270+
271+
def get_pkce_token(self,client_id,code_verifier,auth_code,redirect_uri):
272+
""":param client_id: Client Id to authenticate with
273+
:param code_verifier: Code verifier used to generate the code challenge
274+
:param auth_code: Authorization code
275+
:param redirect_uri: Authorized redirect URI for your Code Authorization client
276+
:return:
277+
"""
278+
279+
self.client_id = client_id
280+
281+
query_params = {}
282+
body = None
283+
url = re.sub(r'\/\/(api)\.', '//login.', self.host) + '/oauth/token'
284+
285+
post_params = {'grant_type': 'authorization_code',
286+
'code': auth_code,
287+
'code_verifier': code_verifier,
288+
'client_id': client_id,
289+
'redirect_uri': redirect_uri
290+
}
291+
292+
header_params = {
293+
'Content-Type': 'application/x-www-form-urlencoded'
294+
}
295+
header_params = self.sanitize_for_serialization(header_params)
296+
post_params = self.sanitize_for_serialization(post_params)
297+
298+
response = self.request("POST", url,
299+
query_params=query_params,
300+
headers=header_params,
301+
post_params=post_params, body=body)
302+
data = json.loads('[' + response.data + ']')
303+
304+
self.access_token = data[0]["access_token"]
305+
306+
return self, data[0]
307+
246308
@property
247309
def user_agent(self):
248310
"""
@@ -295,7 +357,7 @@ def __call_api(self, resource_path, method,
295357
header_params['Cookie'] = self.cookie
296358
if header_params:
297359
header_params = self.sanitize_for_serialization(header_params)
298-
header_params['purecloud-sdk'] = '191.0.0'
360+
header_params['purecloud-sdk'] = '192.0.0'
299361

300362
# path parameters
301363
if path_params:

build/PureCloudPlatformClientV2/apis/architect_api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9519,7 +9519,7 @@ def post_flows_datatable_import_jobs(self, datatable_id: str, body: 'DataTableIm
95199519
def post_flows_datatable_rows(self, datatable_id: str, data_table_row: object, **kwargs) -> Dict[str, object]:
95209520
"""
95219521
Create a new row entry for the datatable.
9522-
Will add the passed in row entry to the datatable with the given datatableId after verifying it against the schema. The DataTableRow should be a json-ized' stream of key -> value pairs { \"Field1\": \"XYZZY\", \"Field2\": false, \"KEY\": \"27272\" }
9522+
Will add the passed in row entry to the datatable with the given datatableId after verifying it against the schema. When building the request body within API Explorer, Pro mode should be used. The DataTableRow should be a json-ized' stream of key -> value pairs { \"Field1\": \"XYZZY\", \"Field2\": false, \"KEY\": \"27272\" }
95239523
95249524
This method makes a synchronous HTTP request by default. To make an
95259525
asynchronous HTTP request, please define a `callback` function
@@ -10916,7 +10916,7 @@ def put_flows_datatable(self, datatable_id: str, body: 'DataTable', **kwargs) ->
1091610916
def put_flows_datatable_row(self, datatable_id: str, row_id: str, **kwargs) -> Dict[str, object]:
1091710917
"""
1091810918
Update a row entry
10919-
Updates a row with the given rowId (the value of the key field) to the new values. The DataTableRow should be a json-ized' stream of key -> value pairs { \"Field1\": \"XYZZY\", \"Field2\": false, \"KEY\": \"27272\" }
10919+
Updates a row with the given rowId (the value of the key field) to the new values. When building the request body within API Explorer, Pro mode should be used. The DataTableRow should be a json-ized' stream of key -> value pairs { \"Field1\": \"XYZZY\", \"Field2\": false, \"KEY\": \"27272\" }
1092010920
1092110921
This method makes a synchronous HTTP request by default. To make an
1092210922
asynchronous HTTP request, please define a `callback` function

build/PureCloudPlatformClientV2/apis/authorization_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1160,7 +1160,7 @@ def get_authorization_role(self, role_id: str, **kwargs) -> 'DomainOrganizationR
11601160
:param callback function: The callback function
11611161
for asynchronous request. (optional)
11621162
:param str role_id: Role ID (required)
1163-
:param bool user_count: Fetch the count of users who have this role granted in at least one division
1163+
:param bool user_count: Fetch the count of users who have this role granted in at least one division. Setting this value or defaulting to 'true' can lead to slower load times or timeouts for role queries with large member counts.
11641164
:param list[str] expand: Which fields, if any, to expand. \"unusedPermissions\" returns the permissions not used for the role
11651165
:return: DomainOrganizationRole
11661166
If the method is called asynchronously,

0 commit comments

Comments
 (0)