-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_apptoken.py
66 lines (51 loc) · 2.08 KB
/
create_apptoken.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from settings import partner_id, admin_secret, userId, role_id, \
privacy_context, token_expiry, apptoken_user, widget_session, enable_entitlement, uri_restrict
import json
from KalturaClient import *
from KalturaClient.Plugins.Core import *
# Administrator generates a session in order to create the app token
config = KalturaConfiguration(partner_id)
config.serviceUrl = "https://www.kaltura.com/"
client = KalturaClient(config)
ks = client.session.start(
admin_secret,
userId,
KalturaSessionType.ADMIN,
partner_id)
client.setKs(ks)
session_privs = ''
# create the app token
appToken = KalturaAppToken()
# Set the role ID provided in settings.py, if applicable
if role_id != '':
session_privs = session_privs + 'setrole:' + str(role_id)
# Set the privacy context, if applicable
if privacy_context != '':
session_privs = session_privs + ',privacycontext:' + privacy_context
# Set the widget session, if applicable
if widget_session != '':
session_privs = session_privs + ',widget:1'
# Set the entitlement check, if applicable
if enable_entitlement != '':
session_privs = session_privs + ',enableentitlement'
# Set the URI restriction, if applicable
if uri_restrict != '':
session_privs = session_privs + ',urirestrict:' + uri_restrict
# Set an optional user to apply during app token creation
if apptoken_user != '':
appToken.sessionUserId = apptoken_user
appToken.hashType = KalturaAppTokenHashType.SHA256
appToken.sessionPrivileges = session_privs
appToken.expiry = token_expiry
result = client.appToken.add(appToken)
# write the app token info to a JSON file for later retrieval
print('Writing app token info to JSON file...')
json_result = json.dumps(str(result.__dict__))
with open('token_' + result.id + '.json', 'w') as outfile:
json.dump(json_result, outfile)
# print the KS used to create the app token
print('Kaltura Admin Session Used: ' + ks)
print('App Token Session privileges applied: ' + result.sessionPrivileges)
# print the app token, app token ID
print('App Token: ' + result.token)
print('App Token ID: ' + result.id)