Skip to content
This repository was archived by the owner on Jun 11, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/Service.gs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,16 @@ Service_.prototype.setMethod = function(method) {
return this;
};

/**
* Sets the OAuth realm parameter to be used with this service (optional).
* @param {string} realm The realm to be used with this service.
* @return {Service_} This service, for chaining.
*/
Service_.prototype.setRealm = function(realm) {
this.realm_ = realm;
return this;
};

/**
* Sets the OAuth signature method to use. 'HMAC-SHA1' is the default.
* @param {string} signatureMethod The OAuth signature method. Allowed values
Expand Down Expand Up @@ -415,6 +425,9 @@ Service_.prototype.fetchInternal_ = function(url, params, opt_token,
request.data = data;
}
oauthParams = signer.authorize(request, token, oauthParams);
if (this.realm_ != null) {
oauthParams.realm = this.realm_;
}
switch (this.paramLocation_) {
case 'auth-header':
params.headers = _.extend({}, params.headers,
Expand Down
3 changes: 2 additions & 1 deletion src/Signer.gs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* https://github.com/ddo/oauth-1.0a
* The cryptojs dependency was removed in favor of native Apps Script functions.
* A new parameter was added to authorize() for additional oauth params.
* Support for realm authorization parameter was added in toHeader().
*/

(function(global) {
Expand Down Expand Up @@ -267,7 +268,7 @@
var header_value = 'OAuth ';

for(var key in oauth_data) {
if (key.indexOf('oauth_') === -1)
if (key !== 'realm' && key.indexOf('oauth_') === -1)
continue;
header_value += this.percentEncode(key) + '="' + this.percentEncode(oauth_data[key]) + '"' + this.parameter_seperator;
}
Expand Down