Skip to content

Commit 3e03f96

Browse files
committed
Create BackenClient with static access token
1 parent 5b8ea6f commit 3e03f96

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

packages/sdk/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
# Changelog
44

5+
## [1.6.2] - 2025-05-20a
6+
7+
### Added
8+
9+
- Added ability to create a `BackendClient` with just an `AccessToken`
10+
511
## [1.6.1] - 2025-05-20
612

713
### Added

packages/sdk/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@pipedream/sdk",
33
"type": "module",
4-
"version": "1.6.1",
4+
"version": "1.6.2",
55
"description": "Pipedream SDK",
66
"main": "./dist/server.js",
77
"module": "./dist/server.js",

packages/sdk/src/server/index.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ export type BackendClientOpts = {
3636
/**
3737
* The credentials to use for authentication against the Pipedream API.
3838
*/
39-
credentials: OAuthCredentials;
39+
credentials: OAuthCredentials | {
40+
accessToken: string;
41+
};
4042

4143
/**
4244
* The base project ID tied to relevant API requests
@@ -188,12 +190,13 @@ export class BackendClient extends BaseClient {
188190
client: oauth.Client
189191
clientAuth: oauth.ClientAuth
190192
as: oauth.AuthorizationServer
191-
};
193+
} | undefined;
192194
private oauthAccessToken?: {
193195
token: string
194196
expiresAt: number
195197
};
196198
protected override projectId: string = "";
199+
private staticAccessToken?: string;
197200

198201
/**
199202
* Constructs a new ServerClient instance.
@@ -206,7 +209,11 @@ export class BackendClient extends BaseClient {
206209

207210
this.ensureValidEnvironment(opts.environment);
208211
this.projectId = opts.projectId;
209-
this.oauthClient = this.newOauthClient(opts.credentials, this.apiHost);
212+
if ("accessToken" in opts.credentials) {
213+
this.staticAccessToken = opts.credentials.accessToken;
214+
} else {
215+
this.oauthClient = this.newOauthClient(opts.credentials, this.apiHost);
216+
}
210217
}
211218

212219
private ensureValidEnvironment(environment?: string) {
@@ -245,10 +252,16 @@ export class BackendClient extends BaseClient {
245252
}
246253

247254
protected authHeaders(): string | Promise<string> {
255+
if (this.staticAccessToken) {
256+
return `Bearer ${this.staticAccessToken}`;
257+
}
248258
return this.oauthAuthorizationHeader();
249259
}
250260

251261
private async ensureValidOauthAccessToken(): Promise<string> {
262+
if (!this.oauthClient) {
263+
throw new Error("OAuth client not configured")
264+
}
252265
const {
253266
client,
254267
clientAuth,
@@ -286,10 +299,6 @@ export class BackendClient extends BaseClient {
286299
}
287300

288301
private async oauthAuthorizationHeader(): Promise<string> {
289-
if (!this.oauthClient) {
290-
throw new Error("OAuth client not configured")
291-
}
292-
293302
const accessToken = await this.ensureValidOauthAccessToken();
294303

295304
return `Bearer ${accessToken}`;

0 commit comments

Comments
 (0)