Skip to content

Commit

Permalink
192.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
PureCloud Jenkins committed Dec 16, 2023
1 parent 36ba926 commit a5ac10f
Show file tree
Hide file tree
Showing 293 changed files with 21,330 additions and 2,799 deletions.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,27 @@ apiclient, auth_token_info = apiclient.refresh_code_authorization_token(os.envir
refresh_token)
```

### PKCE Grant

* The app is authenticating as a human, the [PKCE Grant](https://developer.genesys.cloud/authorization/platform-auth/use-pkce)
* The app is served via a web server
* There is server-side code that will be making API requests

```python
apiclient, auth_token_info = apiclient.get_pkce_token(os.environ['GENESYS_CLOUD_CODEAUTH_CLIENT_ID'],
code_verifier,
auth_code,
"https://redirect-uri.com/oauth/callback")
usersApi = PureCloudPlatformClientV2.UsersApi(apiclient)
```

The SDK provides methods to generate a PKCE Code Verifier and to compute PKCE Code Challenge.

```python
code_verifier = PureCloudPlatformClientV2.api_client.ApiClient().generate_pkce_code_verifier(128)
code_challenge = PureCloudPlatformClientV2.api_client.ApiClient().compute_pkce_code_challenge(code_verifier)
```

### Setting the Environment

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.
Expand Down
134 changes: 132 additions & 2 deletions build/.openapi-generator/FILES

Large diffs are not rendered by default.

4,754 changes: 2,510 additions & 2,244 deletions build/APIData.json

Large diffs are not rendered by default.

61 changes: 60 additions & 1 deletion build/PureCloudPlatformClientV2/__init__.py

Large diffs are not rendered by default.

64 changes: 63 additions & 1 deletion build/PureCloudPlatformClientV2/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
import base64
import json
import time
import string
import hashlib


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

return self, data[0]

def generate_pkce_code_verifier(self,length):
"""
Generate a random string used as PKCE Code Verifier.
"""
if length < 43 or length > 128:
raise ValueError('PKCE Code Verifier (length) must be between 43 and 128 characters')

# Get all the ASCII letters in lowercase and uppercase
unreserved_characters = string.ascii_letters + string.digits + '-' + '.' + '_'
# Randomly choose characters from unreserved_characters for the given length of the string
random_string = ''.join(random.choice(unreserved_characters) for i in range(length))
return random_string

def compute_pkce_code_challenge(self,code):
"""
Compute PKCE Code Challenge from Code Verifier.
"""
if len(code) < 43 or len(code) > 128:
raise ValueError('PKCE Code Verifier (length) must be between 43 and 128 characters')

code_hash = hashlib.sha256(code.encode('ascii'))
return (base64.urlsafe_b64encode(code_hash.digest()).decode('ascii')).split('=')[0]

def get_pkce_token(self,client_id,code_verifier,auth_code,redirect_uri):
""":param client_id: Client Id to authenticate with
:param code_verifier: Code verifier used to generate the code challenge
:param auth_code: Authorization code
:param redirect_uri: Authorized redirect URI for your Code Authorization client
:return:
"""

self.client_id = client_id

query_params = {}
body = None
url = re.sub(r'\/\/(api)\.', '//login.', self.host) + '/oauth/token'

post_params = {'grant_type': 'authorization_code',
'code': auth_code,
'code_verifier': code_verifier,
'client_id': client_id,
'redirect_uri': redirect_uri
}

header_params = {
'Content-Type': 'application/x-www-form-urlencoded'
}
header_params = self.sanitize_for_serialization(header_params)
post_params = self.sanitize_for_serialization(post_params)

response = self.request("POST", url,
query_params=query_params,
headers=header_params,
post_params=post_params, body=body)
data = json.loads('[' + response.data + ']')

self.access_token = data[0]["access_token"]

return self, data[0]

@property
def user_agent(self):
"""
Expand Down Expand Up @@ -295,7 +357,7 @@ def __call_api(self, resource_path, method,
header_params['Cookie'] = self.cookie
if header_params:
header_params = self.sanitize_for_serialization(header_params)
header_params['purecloud-sdk'] = '191.0.0'
header_params['purecloud-sdk'] = '192.0.0'

# path parameters
if path_params:
Expand Down
4 changes: 2 additions & 2 deletions build/PureCloudPlatformClientV2/apis/architect_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -9519,7 +9519,7 @@ def post_flows_datatable_import_jobs(self, datatable_id: str, body: 'DataTableIm
def post_flows_datatable_rows(self, datatable_id: str, data_table_row: object, **kwargs) -> Dict[str, object]:
"""
Create a new row entry for the datatable.
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\" }
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\" }
This method makes a synchronous HTTP request by default. To make an
asynchronous HTTP request, please define a `callback` function
Expand Down Expand Up @@ -10916,7 +10916,7 @@ def put_flows_datatable(self, datatable_id: str, body: 'DataTable', **kwargs) ->
def put_flows_datatable_row(self, datatable_id: str, row_id: str, **kwargs) -> Dict[str, object]:
"""
Update a row entry
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\" }
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\" }
This method makes a synchronous HTTP request by default. To make an
asynchronous HTTP request, please define a `callback` function
Expand Down
2 changes: 1 addition & 1 deletion build/PureCloudPlatformClientV2/apis/authorization_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1160,7 +1160,7 @@ def get_authorization_role(self, role_id: str, **kwargs) -> 'DomainOrganizationR
:param callback function: The callback function
for asynchronous request. (optional)
:param str role_id: Role ID (required)
:param bool user_count: Fetch the count of users who have this role granted in at least one division
: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.
:param list[str] expand: Which fields, if any, to expand. \"unusedPermissions\" returns the permissions not used for the role
:return: DomainOrganizationRole
If the method is called asynchronously,
Expand Down
Loading

0 comments on commit a5ac10f

Please sign in to comment.