Hi @elliottyates,
If you already have an existing token and you need to generate a session using it then you only need:
from KalturaClient import *
from KalturaClient.Plugins.Core import *
import hashlib
partner_id=YOUR_PARTNER_ID
config = KalturaConfiguration(partner_id)
config.serviceUrl = "https://www.kaltura.com/"
client = KalturaClient(config)
id="YOUR_TOKEN_ID"
token="YOUR_TOKEN_HASH"
userId="user@example.com"
# generate a widget session in order to use the app token
widgetId = "_"+str(partner_id)
expiry = 86400
result = client.session.startWidgetSession(widgetId, expiry);
client.setKs(result.ks)
tokenHash = hashlib.sha256(result.ks.encode('ascii')+token.encode('ascii')).hexdigest()
type = KalturaSessionType.ADMIN
# start an app token session
result = client.appToken.startSession(id, tokenHash, userId, type, expiry);
print(result.ks)
Below is a full code sample for creating an app token and then using it to start a session.
from KalturaClient import *
from KalturaClient.Plugins.Core import *
import hashlib
# generate a session in order to create the app token
partner_id=00000001
admin_secret="YOUR_ADMIN_SECRET"
userId = "user@example.com"
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)
# create the app token
appToken = KalturaAppToken()
appToken.hashType = KalturaAppTokenHashType.SHA256
result = client.appToken.add(appToken);
id=result.id;
token=result.token;
# generate a widget session in order to use the app token
widgetId = "_"+str(partner_id)
expiry = 86400
result = client.session.startWidgetSession(widgetId, expiry);
client.setKs(result.ks)
tokenHash = hashlib.sha256(result.ks.encode('ascii')+token.encode('ascii')).hexdigest()
type = KalturaSessionType.ADMIN
# start an app token session
result = client.appToken.startSession(id, tokenHash, userId, type, expiry);
print(result.ks)
Cheers,