From 2c915fb8265a9ce66ddd795c4da3e6915d62e809 Mon Sep 17 00:00:00 2001 From: Alex Chan Date: Wed, 5 Dec 2012 13:10:37 -0600 Subject: [PATCH 1/4] Fixing exp timestamp in capability token. --- src/classes/TwilioCapability.cls | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/classes/TwilioCapability.cls b/src/classes/TwilioCapability.cls index 52fd607..cf4cf47 100644 --- a/src/classes/TwilioCapability.cls +++ b/src/classes/TwilioCapability.cls @@ -119,7 +119,7 @@ global class TwilioCapability { * @return the newly generated token that is valid for 3600 seconds */ global String generateToken() { - return generateToken(System.currentTimeMillis() + 3600); + return generateToken(3600); } /** @@ -137,7 +137,7 @@ global class TwilioCapability { buildOutgoingScope(); Map payload = new Map(); payload.put('iss', this.accountSid); - payload.put('exp', String.valueOf(System.currentTimeMillis() + ttl)); + payload.put('exp', String.valueOf(System.currentTimeMillis()/1000 + ttl)); payload.put('scope', join(this.scopes, ' ')); return jwtEncode(payload, this.authToken); } @@ -326,4 +326,4 @@ global class TwilioCapability { } private class TestOnlyException extends Exception {} -} \ No newline at end of file +} From 455468e43c97687fe2f95f2e642a685018013b1f Mon Sep 17 00:00:00 2001 From: Brett Gerry Date: Tue, 23 Jul 2013 17:04:21 -0700 Subject: [PATCH 2/4] use https instead of http for the GET test --- src/classes/Twilio_TestRest.cls | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/classes/Twilio_TestRest.cls b/src/classes/Twilio_TestRest.cls index bd14a68..fb36e51 100644 --- a/src/classes/Twilio_TestRest.cls +++ b/src/classes/Twilio_TestRest.cls @@ -29,7 +29,7 @@ private class Twilio_TestRest { final static String authToken = '12345678901234567890123456789012'; static testMethod void testTwilioRestResponse() { - String url = 'http://api.twilio.com'; + String url = 'https://api.twilio.com'; String queryString = 'a=1&b=2'; String responseText = 'This is a test'; TwilioRestResponse response = new TwilioRestResponse(url+'?'+queryString,responseText,200); From d029e65ffe4c88a48152c0967c48c2dd620f57e8 Mon Sep 17 00:00:00 2001 From: Brett Gerry Date: Tue, 29 Oct 2013 11:29:26 -0700 Subject: [PATCH 3/4] add Accept-Charset header and update version and agent --- src/classes/TwilioRestClient.cls | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/classes/TwilioRestClient.cls b/src/classes/TwilioRestClient.cls index dc7a5c3..6ddf2a0 100644 --- a/src/classes/TwilioRestClient.cls +++ b/src/classes/TwilioRestClient.cls @@ -28,7 +28,7 @@ OTHER DEALINGS IN THE SOFTWARE. public class TwilioRestClient { /** The Constant VERSION. */ - private static final String VERSION = '3.0'; + private static final String VERSION = '3.1.0'; /** The endpoint. */ private String endpoint = 'https://api.twilio.com'; @@ -524,8 +524,9 @@ public class TwilioRestClient { HttpRequest request = buildMethod(method, path, params); request.setHeader('X-Twilio-Client', 'salesforce-' + VERSION); - request.setHeader('User-Agent', 'twilio-salesforce-' + VERSION); + request.setHeader('User-Agent', 'twilio-salesforce/' + VERSION); request.setHeader('Accept', 'application/json'); + request.setHeader('Accept-Charset', 'utf-8'); request.setHeader('Authorization', 'Basic '+EncodingUtil.base64Encode(Blob.valueOf(this.accountSid + ':' + this.authToken))); From 069947789a605dd028333213de080be2409d54fb Mon Sep 17 00:00:00 2001 From: Brett Gerry Date: Tue, 29 Oct 2013 14:42:04 -0700 Subject: [PATCH 4/4] merge capability token timestamp fix --- src/classes/TwilioCapability.cls | 33 -------------------------------- 1 file changed, 33 deletions(-) diff --git a/src/classes/TwilioCapability.cls b/src/classes/TwilioCapability.cls index 9e93b04..1dc0281 100644 --- a/src/classes/TwilioCapability.cls +++ b/src/classes/TwilioCapability.cls @@ -112,7 +112,6 @@ global class TwilioCapability { this.scopes.add(buildScopeString('stream', 'subscribe', value)); } -<<<<<<< HEAD /** * Generates a new token based on the credentials and permissions that * previously has been granted to this token. @@ -142,38 +141,6 @@ global class TwilioCapability { payload.put('scope', join(this.scopes, ' ')); return jwtEncode(payload, this.authToken); } -======= - /** - * Generates a new token based on the credentials and permissions that - * previously has been granted to this token. - * - * @return the newly generated token that is valid for 3600 seconds - */ - global String generateToken() { - return generateToken(3600); - } - - /** - * Generates a new token based on the credentials and permissions that - * previously has been granted to this token. - * - * @param expiresAt - * the expiration instance of the token. - * @return the newly generated token that is valid for ttl seconds - */ - global String generateToken(long ttl) { - // Build these scopes lazily when we generate tokens so we know - // if we have a default or incoming client name to use - buildIncomingScope(); - buildOutgoingScope(); - Map payload = new Map(); - payload.put('iss', this.accountSid); - payload.put('exp', String.valueOf(System.currentTimeMillis()/1000 + ttl)); - payload.put('scope', join(this.scopes, ' ')); - return jwtEncode(payload, this.authToken); - } ->>>>>>> 2c915fb8265a9ce66ddd795c4da3e6915d62e809 - /* PRIVATE METHODS */