You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
See the [FitBit sample](samples/FitBit.gs) for the compelte code.
189
+
See the [FitBit sample](samples/FitBit.gs) for the complete code.
190
190
191
191
#### Modifying the access token payload
192
192
Similar to Setting additional token headers, some services, such as the Smartsheet API, require you to [add a hash to the access token request payloads](http://smartsheet-platform.github.io/api-docs/?javascript#oauth-flow). The `setTokenPayloadHandler` method allows you to pass in a function to modify the payload of an access token request before the request is sent to the token endpoint:
193
193
194
194
195
-
// Set the handler for adding Smartsheet's required SHA hash parameter to the payload:
196
-
.setTokenPayloadHandler(smartsheetTokenHandler)
197
-
...
198
-
function smartsheetTokenHandler(payload) {
199
-
var codeOrRefreshToken = payload.code ? payload.code : payload.refresh_token;
200
-
var input = SMARTSHEET_CLIENT_SECRET + "|" + codeOrRefreshToken;
201
-
var hash = Utilities.computeDigest(Utilities.DigestAlgorithm.SHA_256,
202
-
input,
203
-
Utilities.Charset.UTF_8);
204
-
hash = hash.map(function(val) {
205
-
// Google appears to treat these as signed bytes, but we need them unsigned...
206
-
if (val < 0)
207
-
val += 256;
208
-
var str = val.toString(16);
209
-
// pad to two hex digits:
210
-
if (str.length == 1)
211
-
str = '0' + str;
212
-
return str;
213
-
});
214
-
payload.hash = hash.join("");
215
-
// Smartsheet doesn't need the client secret sent (secret is verified by the hash)
216
-
if (payload.client_secret) {
217
-
delete payload.client_secret;
218
-
}
219
-
return payload;
220
-
}
195
+
// Set the handler for modifying the access token request payload:
196
+
.setTokenPayloadHandler(myTokenHandler)
221
197
222
-
198
+
See the [Smartsheet sample](samples/Smartsheet.gs) for the complete code.
0 commit comments