Skip to content

Commit e9f0d70

Browse files
committed
Update Guest Issuer API wrapper and token data model
- Align the parameter names with those used in the documentation. - Update the docstrings. - The paramaters are mandatory (may not be `None`). - Use the library restsession to submit the request. The supplied headers will me merged-in with the session's default headers; the Authentication header will replace the default Authentication header.
1 parent 9d51961 commit e9f0d70

File tree

2 files changed

+39
-28
lines changed

2 files changed

+39
-28
lines changed

webexteamssdk/api/guest_issuer.py

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@
4747
import base64
4848
import requests
4949

50-
API_ENDPOINT = 'jwt'
51-
OBJECT_TYPE = 'guest_issuer_token'
50+
API_ENDPOINT = "jwt"
51+
OBJECT_TYPE = "guest_issuer_token"
5252

5353

5454
class GuestIssuerAPI(object):
@@ -76,46 +76,57 @@ def __init__(self, session, object_factory):
7676
self._session = session
7777
self._object_factory = object_factory
7878

79-
def create(self, subject, displayName, issuerToken, expiration, secret):
79+
def create(self, sub, name, iss, exp, secret):
8080
"""Create a new guest issuer using the provided issuer token.
8181
8282
This function returns a guest issuer with an api access token.
8383
8484
Args:
85-
subject(basestring): Unique and public identifier
86-
displayName(basestring): Display Name of the guest user
87-
issuerToken(basestring): Issuer token from developer hub
88-
expiration(basestring): Expiration time as a unix timestamp
89-
secret(basestring): The secret used to sign your guest issuers
85+
sub(basestring): The subject of the token. This is your unique
86+
and public identifier for the guest user. This claim may
87+
contain only letters, numbers, and hyphens.
88+
name(basestring): The display name of the guest user. This will be
89+
the name shown in Webex Teams clients.
90+
iss(basestring): The issuer of the token. Use the Guest
91+
Issuer ID provided in My Webex Teams Apps.
92+
exp(basestring): The exp time of the token, as a UNIX
93+
timestamp in seconds. Use the lowest practical value for the
94+
use of the token. This is not the exp time for the guest
95+
user's session.
96+
secret(basestring): Use the secret Webex provided you when you
97+
created your Guest Issuer App. The secret will be used to sign
98+
the token request.
9099
91100
Returns:
92-
GuestIssuerToken: A Guest Issuer with a valid access token.
101+
GuestIssuerToken: A Guest Issuer token with a valid access token.
93102
94103
Raises:
95104
TypeError: If the parameter types are incorrect
96105
ApiError: If the webex teams cloud returns an error.
97106
"""
98-
check_type(subject, basestring, optional=True)
99-
check_type(displayName, basestring, optional=True)
100-
check_type(issuerToken, basestring, optional=True)
101-
check_type(expiration, basestring, optional=True)
102-
check_type(secret, basestring, optional=True)
107+
check_type(sub, basestring)
108+
check_type(name, basestring)
109+
check_type(iss, basestring)
110+
check_type(exp, basestring)
111+
check_type(secret, basestring)
103112

104113
payload = {
105-
"sub": subject,
106-
"name": displayName,
107-
"iss": issuerToken,
108-
"exp": expiration
114+
"sub": sub,
115+
"name": name,
116+
"iss": iss,
117+
"exp": exp
109118
}
110119

111120
key = base64.b64decode(secret)
112-
jwt_token = jwt.encode(payload, key, algorithm='HS256')
121+
jwt_token = jwt.encode(payload, key, algorithm="HS256")
113122

114-
url = self._session.base_url + API_ENDPOINT + "/" + "login"
115123
headers = {
116-
'Authorization': "Bearer " + jwt_token.decode('utf-8')
124+
"Authorization": "Bearer " + jwt_token.decode("utf-8")
117125
}
118-
response = requests.post(url, headers=headers)
119-
check_response_code(response, EXPECTED_RESPONSE_CODE['GET'])
120126

121-
return self._object_factory(OBJECT_TYPE, response.json())
127+
json_data = self._session.post(
128+
API_ENDPOINT + "/" + "login",
129+
headers=headers
130+
)
131+
132+
return self._object_factory(OBJECT_TYPE, json_data)

webexteamssdk/models/mixins/guest_issuer_token.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ class GuestIssuerTokenBasicPropertiesMixin(object):
3636
"""Guest issuer token basic properties"""
3737

3838
@property
39-
def access_token(self):
40-
return self._json_data.get('token')
39+
def token(self):
40+
return self._json_data.get("token")
4141

4242
@property
43-
def expires_in(self):
44-
return self._json_data.get('expiresIn')
43+
def expiresIn(self):
44+
return self._json_data.get("expiresIn")

0 commit comments

Comments
 (0)