Skip to content

Commit 8797757

Browse files
author
PureCloud Jenkins
committed
57.0.1
1 parent fe0b55b commit 8797757

File tree

141 files changed

+9612
-243
lines changed

Some content is hidden

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

141 files changed

+9612
-243
lines changed

README.md

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,54 @@ import PureCloudPlatformClientV2
2626

2727
### Authenticating
2828

29-
The Python SDK does not currently contain helper methods to complete an OAuth flow. The consuming applicaiton must complete an OAuth flow to get an access token outside the scope of the SDK. Once an access token is obtained, it should be set on the SDK via `PureCloudPlatformClientV2.configuration.access_token`. For more information about authenticating with OAuth, see the Developer Center article [Authorization](https://developer.mypurecloud.com/api/rest/authorization/index.html).
29+
#### Client Credentials Grant
30+
31+
**Use when...**
32+
33+
* The app is authenticating as a non-human (e.g. a service, scheduled task, or other non-UI application)
34+
35+
For headless and non-user applications, the [Client Credentials Grant](http://developer.mypurecloud.com/api/rest/authorization/use-client-credentials.html)
3036

3137
```{"language":"python"}
32-
PureCloudPlatformClientV2.configuration.access_token = 'cuQbSAf1LU4CuIaSj1D6Gm399jmTr7zLTTc3KPSyCvEyJQIo9r648h3SH8oFzLPPKxE3Mvb166lq5NcjSBoGE5A'
38+
apiclient = PureCloudPlatformClientV2.api_client.ApiClient().get_client_credentials_token("7de3af06-c0b3-4f9b-af45-72f4a14037cc", "qLh-825gtjPrIY2kcWKAkmlaSgi6Z1Ws2BAyixWbTrs")
39+
authApi = PureCloudPlatformClientV2.AuthorizationApi(apiclient)
40+
print authApi.get_authorization_permissions()
3341
```
3442

43+
#### OAuth2 SAML2 Bearer Grant
44+
45+
**Use when...**
46+
47+
* The app is authenticating as a human user, the [OAuth2 SAML2 Bearer](https://developer.mypurecloud.com/api/rest/authorization/use-saml2-bearer.html)
48+
49+
```{"language":"python"}
50+
apiclient = PureCloudPlatformClientV2.api_client.ApiClient().get_saml2bearer_token("565c3091-4107-4675-b606-b1fead2d15a4", "9pal483eSr_vCZf0qQomFK298I8htjBZo49FI_lLZQ8", orgName ,encodedsamlassertion)
51+
usersApi = PureCloudPlatformClientV2.UsersApi(apiclient)
52+
print usersApi.get_users_me()
53+
54+
```
55+
56+
57+
3558
### Setting the Environment
3659

3760
If connecting to a PureCloud 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.
3861

3962
```{"language":"python"}
40-
PureCloudPlatformClientV2.configuration.host = 'https://api.mypurecloud.ie'
63+
region = PureCloudRegionHosts.us_east_1
64+
PureCloudPlatformClientV2.configuration.host = region.get_api_host
4165
```
4266

67+
### Connect to a Proxy Server
68+
69+
If connecting to a proxy server, set the the address of your proxy server as follows:
70+
71+
```{"language":"python"}
72+
PureCloudPlatformClientV2.configuration.proxy = 'YOUR_PROXY_URL'
73+
```
74+
75+
The Python SDK uses `urllib3.ProxyManager` to make requests when `proxy` is given.
76+
4377
### Making Requests
4478

4579
There are two steps to making requests:

build/PureCloudPlatformClientV2/__init__.py

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

build/PureCloudPlatformClientV2/api_client.py

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
import random
3333
import tempfile
3434
import threading
35+
import base64
36+
import json
37+
3538

3639
from datetime import datetime
3740
from datetime import date
@@ -87,6 +90,74 @@ def __init__(self, host=None, header_name=None, header_value=None, cookie=None):
8790
self.access_token = ""
8891

8992

93+
94+
def get_client_credentials_token(self, client_id, client_secret):
95+
"""
96+
:param client_id: Client ID to authenticate with
97+
:param client_secret: Client Secret to Authenticate with
98+
:return: Returns the Api Object which allows this to directly enter into an api call, also sets the token
99+
"""
100+
query_params = {}
101+
body = None
102+
host = (self.host).split('.', 2)[1]
103+
url = 'https://login.' + host + '.com/oauth/token'
104+
105+
post_params = {'grant_type': 'client_credentials'}
106+
107+
auth_string = 'Basic ' + base64.b64encode(bytes((client_id + ':' + client_secret).encode('ascii'))).decode(
108+
'ascii')
109+
110+
header_params = {
111+
"Authorization": auth_string,
112+
'Content-Type': 'application/x-www-form-urlencoded'
113+
}
114+
header_params = self.sanitize_for_serialization(header_params)
115+
post_params = self.sanitize_for_serialization(post_params)
116+
117+
response = self.request("POST", url,
118+
query_params=query_params,
119+
headers=header_params,
120+
post_params=post_params, body=body);
121+
data = json.loads('[' + response.data + ']')
122+
self.access_token = data[0]["access_token"]
123+
return self;
124+
125+
def get_saml2bearer_token(self,client_id,client_secret,org_name,assertion):
126+
""":param client_id: Client Id to authenticate with
127+
:param client_secret: Client Secret to authenticate with
128+
:param org_name: Orginization name to authenticate with
129+
:param assertion: SamlAssertion encoded
130+
:return:
131+
"""
132+
133+
query_params = {}
134+
body = None
135+
host = (self.host).split('.', 2)[1]
136+
url = 'https://login.' + host + '.com/oauth/token'
137+
138+
post_params = {'grant_type': 'urn:ietf:params:oauth:grant-type:saml2-bearer',
139+
'orgName': org_name,
140+
'assertion': assertion
141+
}
142+
143+
auth_string = 'Basic ' + base64.b64encode(bytes((client_id + ':' + client_secret).encode('ascii'))).decode(
144+
'ascii')
145+
146+
header_params = {
147+
"Authorization": auth_string,
148+
'Content-Type': 'application/x-www-form-urlencoded'
149+
}
150+
header_params = self.sanitize_for_serialization(header_params)
151+
post_params = self.sanitize_for_serialization(post_params)
152+
153+
response = self.request("POST", url,
154+
query_params=query_params,
155+
headers=header_params,
156+
post_params=post_params, body=body);
157+
data = json.loads('[' + response.data + ']')
158+
self.access_token = data[0]["access_token"]
159+
return self;
160+
90161
@property
91162
def user_agent(self):
92163
"""
@@ -116,7 +187,7 @@ def __call_api(self, resource_path, method,
116187
header_params['Cookie'] = self.cookie
117188
if header_params:
118189
header_params = self.sanitize_for_serialization(header_params)
119-
header_params['purecloud-sdk'] = '57.0.0'
190+
header_params['purecloud-sdk'] = '57.0.1'
120191

121192
# path parameters
122193
if path_params:

build/PureCloudPlatformClientV2/configuration.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ def __init__(self):
101101
# client key file
102102
self.key_file = None
103103

104+
# proxy
105+
self.proxy = None
106+
104107
@property
105108
def logger_file(self):
106109
"""
@@ -246,5 +249,5 @@ def to_debug_report(self):
246249
"OS: {env}\n"\
247250
"Python Version: {pyversion}\n"\
248251
"Version of the API: v2\n"\
249-
"SDK Package Version: 57.0.0".\
252+
"SDK Package Version: 57.0.1".\
250253
format(env=sys.platform, pyversion=sys.version)

0 commit comments

Comments
 (0)