27
27
28
28
/**
29
29
* The supported formats for the returned OAuth2 token.
30
- * @type { Object.< string, string> }
30
+ * @enum { string}
31
31
*/
32
32
var TOKEN_FORMAT = {
33
+ /** JSON format, for example <code>{"access_token": "..."}</code> **/
33
34
JSON : 'application/json' ,
35
+ /** Form URL-encoded, for example <code>access_token=...</code> **/
34
36
FORM_URL_ENCODED : 'application/x-www-form-urlencoded'
35
37
} ;
36
38
37
39
/**
38
40
* The supported locations for passing the state parameter.
39
- * @type { Object.< string, string> }
41
+ * @enum { string}
40
42
*/
41
43
var STATE_PARAMETER_LOCATION = {
44
+ /**
45
+ * Pass the state parameter in the authorization URL.
46
+ * @default
47
+ */
42
48
AUTHORIZATION_URL : 'authorization-url' ,
49
+ /** Pass the state token in the redirect URL, as a workaround for APIs that don't support the state parameter. */
43
50
REDIRECT_URL : 'redirect-url'
44
51
} ;
45
52
@@ -153,17 +160,28 @@ Service_.prototype.setTokenFormat = function(tokenFormat) {
153
160
/**
154
161
* Sets the additional HTTP headers that should be sent when retrieving or
155
162
* refreshing the access token.
156
- * @param Object.<string,string> tokenHeaders A map of header names to values.
163
+ * @param { Object.<string,string> } tokenHeaders A map of header names to values.
157
164
* @return {Service_ } This service, for chaining.
158
165
*/
159
166
Service_ . prototype . setTokenHeaders = function ( tokenHeaders ) {
160
167
this . tokenHeaders_ = tokenHeaders ;
161
168
return this ;
162
169
} ;
163
170
171
+ /**
172
+ * @callback tokenHandler
173
+ * @param tokenPayload {Object} A hash of parameters to be sent to the token URL.
174
+ * @param tokenPayload.code {string} The authorization code.
175
+ * @param tokenPayload.client_id {string} The client ID.
176
+ * @param tokenPayload.client_secret {string} The client secret.
177
+ * @param tokenPayload.redirect_uri {string} The redirect URI.
178
+ * @param tokenPayload.grant_type {string} The type of grant requested.
179
+ * @returns {Object } A modified hash of parameters to be sent to the token URL.
180
+ */
181
+
164
182
/**
165
183
* Sets an additional function to invoke on the payload of the access token request.
166
- * @param Object tokenHandler A function to invoke on the payload of the request for an access token.
184
+ * @param tokenHandler {tokenHandler} tokenHandler A function to invoke on the payload of the request for an access token.
167
185
* @return {Service_ } This service, for chaining.
168
186
*/
169
187
Service_ . prototype . setTokenPayloadHandler = function ( tokenHandler ) {
@@ -436,7 +454,11 @@ Service_.prototype.reset = function() {
436
454
validate_ ( {
437
455
'Property store' : this . propertyStore_
438
456
} ) ;
439
- this . propertyStore_ . deleteProperty ( this . getPropertyKey_ ( this . serviceName_ ) ) ;
457
+ var key = this . getPropertyKey_ ( this . serviceName_ ) ;
458
+ this . propertyStore_ . deleteProperty ( key ) ;
459
+ if ( this . cache_ ) {
460
+ this . cache_ . remove ( key ) ;
461
+ }
440
462
} ;
441
463
442
464
/**
@@ -449,9 +471,9 @@ Service_.prototype.getLastError = function() {
449
471
} ;
450
472
451
473
/**
452
- * Gets the last error that occurred this execution when trying to automatically refresh
453
- * or generate an access token .
454
- * @return {Exception } An error, if any .
474
+ * Returns the redirect URI that will be used for this service. Often this URI
475
+ * needs to be entered into a configuration screen of your OAuth provider .
476
+ * @return {string } The redirect URI .
455
477
*/
456
478
Service_ . prototype . getRedirectUri = function ( ) {
457
479
return getRedirectUri ( this . scriptId_ ) ;
@@ -627,6 +649,7 @@ Service_.prototype.isExpired_ = function(token) {
627
649
/**
628
650
* Uses the service account flow to exchange a signed JSON Web Token (JWT) for an
629
651
* access token.
652
+ * @private
630
653
*/
631
654
Service_ . prototype . exchangeJwt_ = function ( ) {
632
655
validate_ ( {
0 commit comments