@@ -56,6 +56,11 @@ export type BackendClientOpts = {
5656 * https://pipedream.com/docs/workflows/domains
5757 */
5858 workflowDomain ?: string ;
59+
60+ /**
61+ * OAuth scope to request when obtaining access tokens
62+ */
63+ scope ?: string [ ] ;
5964} ;
6065
6166/**
@@ -197,6 +202,7 @@ export class BackendClient extends BaseClient {
197202 } ;
198203 protected override projectId : string = "" ;
199204 private staticAccessToken ?: string ;
205+ private scope ?: string [ ] ;
200206
201207 /**
202208 * Constructs a new ServerClient instance.
@@ -209,6 +215,7 @@ export class BackendClient extends BaseClient {
209215
210216 this . ensureValidEnvironment ( opts . environment ) ;
211217 this . projectId = opts . projectId ;
218+ this . scope = opts . scope ;
212219 if ( "accessToken" in opts . credentials ) {
213220 this . staticAccessToken = opts . credentials . accessToken ;
214221 } else {
@@ -264,6 +271,16 @@ export class BackendClient extends BaseClient {
264271 return this . ensureValidOauthAccessToken ( ) ;
265272 }
266273
274+ /**s
275+ * Returns true if the client is configured to use a static access token.
276+ *
277+ * @returns True if the client is configured to use a static access token.
278+ *
279+ */
280+ public isStaticAccessToken ( ) : boolean {
281+ return ! ! this . staticAccessToken ;
282+ }
283+
267284 protected authHeaders ( ) : string | Promise < string > {
268285 if ( this . staticAccessToken ) {
269286 return `Bearer ${ this . staticAccessToken } ` ;
@@ -294,14 +311,18 @@ export class BackendClient extends BaseClient {
294311 }
295312
296313 const parameters = new URLSearchParams ( ) ;
314+ if ( this . scope && this . scope . length > 0 ) {
315+ parameters . set ( "scope" , this . scope . join ( " " ) ) ;
316+ }
297317 try {
298318 const response = await oauth . clientCredentialsGrantRequest ( as , client , clientAuth , parameters ) ;
299319 const oauthTokenResponse = await oauth . processClientCredentialsResponse ( as , client , response ) ;
300320 this . oauthAccessToken = {
301321 token : oauthTokenResponse . access_token ,
302322 expiresAt : Date . now ( ) + ( oauthTokenResponse . expires_in || 0 ) * 1000 ,
303323 } ;
304- } catch {
324+ } catch ( e ) {
325+ console . log ( e )
305326 // pass
306327 }
307328
0 commit comments