Skip to content

Commit b92dc51

Browse files
committed
fix token encoding issue where expiretime was getting truncated
1 parent 83dac22 commit b92dc51

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ archivesBaseName = 'opentok'
99
// TODO: how do we increment this before/after a release for deployment and development?
1010
version = '2.2.0-pre'
1111

12-
sourceCompatibility = 1.5
12+
sourceCompatibility = 1.6
1313

1414
task javadocJar(type: Jar) {
1515
classifier = 'javadoc'

src/main/java/com/opentok/Session.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ public String generateToken(TokenOptions tokenOptions) throws OpenTokException {
124124
throw new InvalidArgumentException(
125125
"Expire time must be in the next 30 days. too large by "+ (expireTime - (now + (60*60*24*30))));
126126
}
127-
dataStringBuilder.append("&expire_time=");
128-
dataStringBuilder.append(expireTime);
127+
// NOTE: Double.toString() would print the value with scientific notation
128+
dataStringBuilder.append(String.format("&expire_time=%.0f", expireTime));
129129

130130
if (data != null) {
131131
if(data.length() > 1000) {
@@ -156,7 +156,13 @@ public String generateToken(TokenOptions tokenOptions) throws OpenTokException {
156156
innerBuilder.append(":");
157157
innerBuilder.append(dataStringBuilder.toString());
158158

159-
tokenStringBuilder.append(Base64.encodeBase64URLSafeString(innerBuilder.toString().getBytes("UTF-8")));
159+
tokenStringBuilder.append(
160+
Base64.encodeBase64String(
161+
innerBuilder.toString().getBytes("UTF-8")
162+
)
163+
.replace("+", "-")
164+
.replace("/", "_")
165+
);
160166

161167
// if we only wanted Java 7 and above, we could DRY this into one catch clause
162168
} catch (SignatureException e) {

src/test/java/com/opentok/test/OpenTokTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,9 @@ public void testTokenExpireTime() throws
243243
assertTrue(Helpers.verifyTokenSignature(oneHourToken, apiSecret));
244244

245245
Map<String, String> defaultTokenData = Helpers.decodeToken(defaultToken);
246-
assertEquals(Double.toString(inOneDay), defaultTokenData.get("expire_time"));
246+
assertEquals(Long.toString(inOneDay), defaultTokenData.get("expire_time"));
247247
Map<String, String> oneHourTokenData = Helpers.decodeToken(oneHourToken);
248-
assertEquals(Double.toString(inOneHour), oneHourTokenData.get("expire_time"));
248+
assertEquals(Long.toString(inOneHour), oneHourTokenData.get("expire_time"));
249249
assertEquals(2, exceptions.size());
250250
for (Exception e : exceptions) {
251251
assertEquals(InvalidArgumentException.class, e.getClass());

0 commit comments

Comments
 (0)