diff --git a/src/Service.gs b/src/Service.gs index cedde21..72a2b59 100644 --- a/src/Service.gs +++ b/src/Service.gs @@ -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 @@ -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, diff --git a/src/Signer.gs b/src/Signer.gs index f1285cd..7d3d565 100644 --- a/src/Signer.gs +++ b/src/Signer.gs @@ -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) { @@ -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; }