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
Copy file name to clipboardExpand all lines: README.md
+33Lines changed: 33 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -188,6 +188,39 @@ in these requests.
188
188
189
189
See the [FitBit sample](samples/FitBit.gs) for the compelte code.
190
190
191
+
#### Modifying the access token payload
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
+
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
+
}
221
+
222
+
223
+
191
224
#### Service Accounts
192
225
193
226
This library supports the service account authorization flow, also known as the
0 commit comments