Skip to content

Commit 47e0b35

Browse files
author
Eric Koleda
committed
Updated README to include setTokenHeaders() method.
1 parent f1caec9 commit 47e0b35

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

README.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ fix the problem yourself and make a pull request against the source code.
153153

154154
## Other features
155155

156-
#### Resetting the Access Token
156+
#### Resetting the access token
157157

158158
If you have an access token set and need to remove it from the property store
159159
you can remove it with the `reset()` function. Before you can call reset you
@@ -165,26 +165,26 @@ need to set the property store.
165165
.reset();
166166
}
167167

168-
#### Setting the Token Format
168+
#### Setting the token format
169169

170170
OAuth services can return a token in two ways: as JSON or an URL encoded
171171
string. You can set which format the token is in with
172172
`setTokenFormat(tokenFormat)`. There are two ENUMS to set the mode:
173173
`TOKEN_FORMAT.FORM_URL_ENCODED` and `TOKEN_FORMAT.JSON`. JSON is set as default
174174
if no token format is chosen.
175175

176-
function gitService() {
177-
return OAuth2.createService('git')
178-
.setAuthorizationBaseUrl('https://github.com/login/oauth/authorize')
179-
.setTokenUrl('https://github.com/login/oauth/access_token')
180-
.setClientId('...')
181-
.setClientSecret('...')
182-
.setProjectKey('...')
183-
.setCallbackFunction('authCallback')
184-
.setPropertyStore(PropertiesService.getUserProperties())
185-
.setScope('gist,repo,user')
186-
.setTokenFormat(OAuth2.TOKEN_FORMAT.FORM_URL_ENCODED);
187-
}
176+
#### Setting additional token headers
177+
178+
Some services, such as the FitBit API, require you to set an Authorization
179+
header on access token requests. The `setTokenHeaders()` method allows you
180+
to pass in a JavaScript object of additional header key/value pairs to be used
181+
in these requests.
182+
183+
.setTokenHeaders({
184+
'Authorization': 'Basic ' + Utilities.base64Encode(CLIENT_ID + ':' + CLIENT_SECRET)
185+
});
186+
187+
See the [FitBit sample](samples/FitBit.gs) for the compelte code.
188188

189189
#### Service Accounts
190190

@@ -199,5 +199,5 @@ This process allows a Google Apps for Work/EDU domain administrator to grant an
199199
application access to all the users within the domain. When the application
200200
wishes to access the resources of a particular user, it uses the service account
201201
authorization flow to obtain an access token. See the sample
202-
[`GoogleServiceAccount.gs`](https://github.com/googlesamples/apps-script-oauth2/blob/master/samples/GoogleServiceAccount.gs)
203-
for more information.
202+
[`GoogleServiceAccount.gs`](samples/GoogleServiceAccount.gs) for more
203+
information.

0 commit comments

Comments
 (0)