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

Commit 9398b17

Browse files
committed
Add OAuth1 realm parameter.
Adds an option to send a `realm="..."` parameter in the Authentication headers, for example: ``` function getService() { return OAuth1.createService("NetSuite") .setRealm('1234567_SB1') .setConsumerKey(CONSUMER_KEY) .setConsumerSecret(CONSUMER_SECRET) .setAccessToken(TOKEN, TOKEN_SECRET); } ```
1 parent 3ad32cc commit 9398b17

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "apps-script-oauth1",
3-
"version": "1.15.0",
3+
"version": "1.16.0",
44
"description": "OAuth1 for Apps Script is a library for Google Apps Script that provides the ability to create and authorize OAuth1 tokens. ",
55
"repository": {
66
"type": "git",

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@
267267
var header_value = 'OAuth ';
268268

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

0 commit comments

Comments
 (0)