Skip to content

Commit 43291d9

Browse files
authored
Add background script for OAuth token handling example
This script demonstrates how to use the OAuthClientCredsHelper for automatic OAuth bearer token handling in API calls.
1 parent e669bb2 commit 43291d9

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Background Script example: call an API with automatic OAuth bearer handling
2+
(function() {
3+
var helper = new OAuthClientCredsHelper();
4+
5+
var options = {
6+
// Token settings
7+
tokenUrl: 'https://auth.example.com/oauth2/token',
8+
clientId: 'YOUR_CLIENT_ID',
9+
clientSecret: 'YOUR_CLIENT_SECRET', // store securely in real environments
10+
scope: 'read:things', // optional
11+
audience: '', // optional (for some IdPs)
12+
propPrefix: 'x_acme.oauth.sample', // system property prefix for cache
13+
14+
// Resource request
15+
resource: 'https://api.example.com/v1/things?limit=25',
16+
method: 'GET',
17+
headers: { 'Accept': 'application/json' }
18+
};
19+
20+
var res = helper.request(options);
21+
gs.info('Status: ' + res.status + ', refreshed=' + res.refreshed);
22+
gs.info('Body: ' + res.body);
23+
})();

0 commit comments

Comments
 (0)