This is how I pass token expiry in days:
tokenOptions.Add(TokenPropertyConstants.EXPIRE_TIME, new DateTime(2014, 03, 24)); //date of tomorrow
My main problem is that I need to set EXPIRE_TIME
from the server side.
How do I fix EXPIRE_TIME
15 minutes from creation time?
I tried this, but it's not working:
tokenOptions.Add(TokenPropertyConstants.EXPIRE_TIME, new DateTime(2014, 03, 23, 18, 20, 00)); //15 minutes more than current time
The code under tokenOptions where EXPIRE_TIME is going looks like this
public string GenerateToken(string sessionId)
{
Dictionary<string, object> options = new Dictionary<string, object>();
return GenerateToken(sessionId, options);
}
public string GenerateToken(string sessionId, Dictionary<string, object> options)
{
NameValueCollection appSettings = ConfigurationManager.AppSettings;
options.Add("session_id", sessionId);
options.Add("create_time", (int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds);
options.Add("nonce", RandomNumber(0, 999999));
if (!options.ContainsKey(TokenPropertyConstants.ROLE))
{
options.Add(TokenPropertyConstants.ROLE, "publisher");
}
// Convert expire time to Unix Timestamp
if (options.ContainsKey(TokenPropertyConstants.EXPIRE_TIME))
{
DateTime origin = new DateTime(1970, 1, 1, 0, 0, 0);
DateTime expireTime = (DateTime)options[TokenPropertyConstants.EXPIRE_TIME];
TimeSpan diff = expireTime - origin;
options[TokenPropertyConstants.EXPIRE_TIME] = Math.Floor(diff.TotalSeconds);
}
string dataString = string.Empty;
foreach (KeyValuePair<string, object> pair in options)
{
dataString += pair.Key + "=" + HttpUtility.UrlEncode(pair.Value.ToString()) + "&";
}
dataString = dataString.TrimEnd('&');
string sig = SignString(dataString, appSettings["opentok_secret"].Trim());
string token = string.Format("{0}{1}", appSettings["opentok_token_sentinel"], EncodeTo64(string.Format("partner_id={0}&sdk_version={1}&sig={2}:{3}", appSettings["opentok_key"], appSettings["opentok_sdk_version"], sig, dataString)));
return token;
}
When tokens expire, users do not automatically get kicked out of a session. The session continues until the users leaves the session. When the user tries to join the session again, their expired token will prevent them from joining.
What I would do is set a timeout on the client side and call session.disconnect() after 15 minutes. If they try to connect again, it will not work since the token would have expired.