|
47 | 47 | import base64
|
48 | 48 | import requests
|
49 | 49 |
|
50 |
| -API_ENDPOINT = 'jwt' |
51 |
| -OBJECT_TYPE = 'guest_issuer_token' |
| 50 | +API_ENDPOINT = "jwt" |
| 51 | +OBJECT_TYPE = "guest_issuer_token" |
52 | 52 |
|
53 | 53 |
|
54 | 54 | class GuestIssuerAPI(object):
|
@@ -76,46 +76,57 @@ def __init__(self, session, object_factory):
|
76 | 76 | self._session = session
|
77 | 77 | self._object_factory = object_factory
|
78 | 78 |
|
79 |
| - def create(self, subject, displayName, issuerToken, expiration, secret): |
| 79 | + def create(self, sub, name, iss, exp, secret): |
80 | 80 | """Create a new guest issuer using the provided issuer token.
|
81 | 81 |
|
82 | 82 | This function returns a guest issuer with an api access token.
|
83 | 83 |
|
84 | 84 | 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. |
90 | 99 |
|
91 | 100 | Returns:
|
92 |
| - GuestIssuerToken: A Guest Issuer with a valid access token. |
| 101 | + GuestIssuerToken: A Guest Issuer token with a valid access token. |
93 | 102 |
|
94 | 103 | Raises:
|
95 | 104 | TypeError: If the parameter types are incorrect
|
96 | 105 | ApiError: If the webex teams cloud returns an error.
|
97 | 106 | """
|
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) |
103 | 112 |
|
104 | 113 | 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 |
109 | 118 | }
|
110 | 119 |
|
111 | 120 | key = base64.b64decode(secret)
|
112 |
| - jwt_token = jwt.encode(payload, key, algorithm='HS256') |
| 121 | + jwt_token = jwt.encode(payload, key, algorithm="HS256") |
113 | 122 |
|
114 |
| - url = self._session.base_url + API_ENDPOINT + "/" + "login" |
115 | 123 | headers = {
|
116 |
| - 'Authorization': "Bearer " + jwt_token.decode('utf-8') |
| 124 | + "Authorization": "Bearer " + jwt_token.decode("utf-8") |
117 | 125 | }
|
118 |
| - response = requests.post(url, headers=headers) |
119 |
| - check_response_code(response, EXPECTED_RESPONSE_CODE['GET']) |
120 | 126 |
|
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) |
0 commit comments