Skip to content

Commit 4b1b3ff

Browse files
author
Eric Koleda
committed
Merge branch 'master' of github.com:googlesamples/apps-script-oauth2 into locking
2 parents 55f584a + 5826d89 commit 4b1b3ff

File tree

17 files changed

+253
-1631
lines changed

17 files changed

+253
-1631
lines changed

README.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ code editor:
2424
Alternatively, you can copy and paste the files in the [`/dist`](dist) directory
2525
directly into your script project.
2626

27+
If you are [setting explicit scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes)
28+
in your manifest file, ensure that the following scope is included:
29+
30+
* `https://www.googleapis.com/auth/script.external_request`
31+
2732
## Redirect URI
2833

2934
Before you can start authenticating against an OAuth2 provider, you usually need
@@ -169,11 +174,11 @@ function makeRequest() {
169174
}
170175
```
171176

172-
## Compatiblity
177+
## Compatibility
173178

174179
This library was designed to work with any OAuth2 provider, but because of small
175180
differences in how they implement the standard it may be that some APIs
176-
aren't compatible. If you find an API that it does't work with, open an issue or
181+
aren't compatible. If you find an API that it doesn't work with, open an issue or
177182
fix the problem yourself and make a pull request against the source code.
178183

179184
## Other features
@@ -260,3 +265,12 @@ registered with the OAuth provider is updated to use the format
260265
`https://script.google.com/macros/d/{SCRIPT ID}/usercallback`.
261266
* Version 22 - Renamed `Service.getToken_()` to `Service.getToken()`, since
262267
there OAuth providers that return important information in the token response.
268+
269+
## Troubleshooting
270+
271+
### You do not have permission to call fetch
272+
273+
You are [setting explicit scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes)
274+
in your manifest file but have forgotten to add the
275+
`https://www.googleapis.com/auth/script.external_request` scope used by this library
276+
(and eventually the `UrlFetchApp` request you are making to an API).

dist/OAuth2.gs

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@
2121
* any required setup.
2222
*/
2323

24-
// Load the Underscore.js library. This library was added using the script
25-
// ID "1I21uLOwDKdyF3_W_hvh6WXiIKWJWno8yG9lB8lf1VBnZFQ6jAAhyNTRG".
26-
27-
2824
/**
2925
* The supported formats for the returned OAuth2 token.
3026
* @enum {string}
@@ -264,7 +260,7 @@ Service_.prototype.setCache = function(cache) {
264260
*/
265261
Service_.prototype.setScope = function(scope, opt_separator) {
266262
var separator = opt_separator || ' ';
267-
this.params_.scope = _.isArray(scope) ? scope.join(separator) : scope;
263+
this.params_.scope = Array.isArray(scope) ? scope.join(separator) : scope;
268264
return this;
269265
};
270266

@@ -766,24 +762,12 @@ function buildUrl_(url, params) {
766762
function validate_(params) {
767763
Object.keys(params).forEach(function(name) {
768764
var value = params[name];
769-
if (isEmpty_(value)) {
765+
if (!value) {
770766
throw Utilities.formatString('%s is required.', name);
771767
}
772768
});
773769
}
774770

775-
/**
776-
* Returns true if the given value is empty, false otherwise. An empty value is one of
777-
* null, undefined, a zero-length string, a zero-length array or an object with no keys.
778-
* @param {?} value The value to test.
779-
* @returns {boolean} True if the value is empty, false otherwise.
780-
* @private
781-
*/
782-
function isEmpty_(value) {
783-
return value === null || value === undefined ||
784-
((_.isObject(value) || _.isString(value)) && _.isEmpty(value));
785-
}
786-
787771
/**
788772
* Gets the time in seconds, rounded down to the nearest second.
789773
* @param {Date} date The Date object to convert.

0 commit comments

Comments
 (0)