File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed
Integration/RESTMessageV2/Auth2 client credentials token cache with auto-refresh Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change 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+ } ) ( ) ;
You can’t perform that action at this time.
0 commit comments