Skip to content
This repository was archived by the owner on Jun 11, 2025. It is now read-only.

Commit 0c1aaa8

Browse files
author
Eric Koleda
authored
Merge pull request #44 from alephyud/add-realm-parameter
Add OAuth1 realm parameter.
2 parents 3ad32cc + edcdf0c commit 0c1aaa8

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/Service.gs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,16 @@ Service_.prototype.setMethod = function(method) {
101101
return this;
102102
};
103103

104+
/**
105+
* Sets the OAuth realm parameter to be used with this service (optional).
106+
* @param {string} realm The realm to be used with this service.
107+
* @return {Service_} This service, for chaining.
108+
*/
109+
Service_.prototype.setRealm = function(realm) {
110+
this.realm_ = realm;
111+
return this;
112+
};
113+
104114
/**
105115
* Sets the OAuth signature method to use. 'HMAC-SHA1' is the default.
106116
* @param {string} signatureMethod The OAuth signature method. Allowed values
@@ -415,6 +425,9 @@ Service_.prototype.fetchInternal_ = function(url, params, opt_token,
415425
request.data = data;
416426
}
417427
oauthParams = signer.authorize(request, token, oauthParams);
428+
if (this.realm_ != null) {
429+
oauthParams.realm = this.realm_;
430+
}
418431
switch (this.paramLocation_) {
419432
case 'auth-header':
420433
params.headers = _.extend({}, params.headers,

src/Signer.gs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
* https://github.com/ddo/oauth-1.0a
2525
* The cryptojs dependency was removed in favor of native Apps Script functions.
2626
* A new parameter was added to authorize() for additional oauth params.
27+
* Support for realm authorization parameter was added in toHeader().
2728
*/
2829

2930
(function(global) {
@@ -267,7 +268,7 @@
267268
var header_value = 'OAuth ';
268269

269270
for(var key in oauth_data) {
270-
if (key.indexOf('oauth_') === -1)
271+
if (key !== 'realm' && key.indexOf('oauth_') === -1)
271272
continue;
272273
header_value += this.percentEncode(key) + '="' + this.percentEncode(oauth_data[key]) + '"' + this.parameter_seperator;
273274
}

0 commit comments

Comments
 (0)