Skip to content

Commit 1ecea61

Browse files
committed
Merge pull request #4 from rpardini/master
Fix user token generation when connection_data contains UTF-8 chars.
2 parents 0ac9707 + 7f0b7f8 commit 1ecea61

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/main/java/com/opentok/api/OpenTokSDK.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
package com.opentok.api;
1212

13+
import java.io.UnsupportedEncodingException;
1314
import java.net.URLEncoder;
1415
import java.util.Arrays;
1516
import java.util.Date;
@@ -67,7 +68,7 @@ public String generate_token(String session_id, String role, Long expire_time, S
6768
throw new OpenTokException(role + " is not a recognized role");
6869

6970
if(expire_time != null) {
70-
if(expire_time < System.currentTimeMillis() / 1000)
71+
if(expire_time < (System.currentTimeMillis() / 1000)-1)
7172
throw new OpenTokException("Expire time must be in the future");
7273
if(expire_time > (System.currentTimeMillis() / 1000 + 2592000))
7374
throw new OpenTokException("Expire time must be in the next 30 days");
@@ -78,7 +79,11 @@ public String generate_token(String session_id, String role, Long expire_time, S
7879
if(connection_data.length() > 1000)
7980
throw new OpenTokException("Connection data must be less than 1000 characters");
8081
data_string_builder.append("&connection_data=");
81-
data_string_builder.append(connection_data);
82+
try {
83+
data_string_builder.append(URLEncoder.encode(connection_data, "UTF-8"));
84+
} catch (UnsupportedEncodingException e) {
85+
throw new RuntimeException("Error during URL encode of your connection_data.", e);
86+
};
8287
}
8388

8489

0 commit comments

Comments
 (0)