-
Couldn't load subscription status.
- Fork 5.5k
Je/add scopes to connect sdk #17452
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Je/add scopes to connect sdk #17452
Changes from 4 commits
b0e555c
7c978a8
745e3b4
4192b82
90f4f85
dcb774a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,4 +8,4 @@ export default { | |
| console.log(Object.keys(this.$auth)); | ||
| }, | ||
| }, | ||
| }; | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,4 +8,4 @@ export default { | |
| console.log(Object.keys(this.$auth)); | ||
| }, | ||
| }, | ||
| }; | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,4 +8,4 @@ export default { | |
| console.log(Object.keys(this.$auth)); | ||
| }, | ||
| }, | ||
| }; | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,4 +8,4 @@ export default { | |
| console.log(Object.keys(this.$auth)); | ||
| }, | ||
| }, | ||
| }; | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,4 +8,4 @@ export default { | |
| console.log(Object.keys(this.$auth)); | ||
| }, | ||
| }, | ||
| }; | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,4 +8,4 @@ export default { | |
| console.log(Object.keys(this.$auth)); | ||
| }, | ||
| }, | ||
| }; | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,4 +8,4 @@ export default { | |
| console.log(Object.keys(this.$auth)); | ||
| }, | ||
| }, | ||
| }; | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,4 +8,4 @@ export default { | |
| console.log(Object.keys(this.$auth)); | ||
| }, | ||
| }, | ||
| }; | ||
| }; | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -56,6 +56,11 @@ | |||||||||||||||||||||||||||||
| * https://pipedream.com/docs/workflows/domains | ||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||
| workflowDomain?: string; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||
| * OAuth scope to request when obtaining access tokens | ||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||
| scope?: string[]; | ||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||
|
|
@@ -197,6 +202,7 @@ | |||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||
| protected override projectId: string = ""; | ||||||||||||||||||||||||||||||
| private staticAccessToken?: string; | ||||||||||||||||||||||||||||||
| private scope?: string[]; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||
| * Constructs a new ServerClient instance. | ||||||||||||||||||||||||||||||
|
|
@@ -209,6 +215,7 @@ | |||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| this.ensureValidEnvironment(opts.environment); | ||||||||||||||||||||||||||||||
| this.projectId = opts.projectId; | ||||||||||||||||||||||||||||||
| this.scope = opts.scope; | ||||||||||||||||||||||||||||||
| if ("accessToken" in opts.credentials) { | ||||||||||||||||||||||||||||||
| this.staticAccessToken = opts.credentials.accessToken; | ||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||
|
|
@@ -264,6 +271,16 @@ | |||||||||||||||||||||||||||||
| return this.ensureValidOauthAccessToken(); | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| /**s | ||||||||||||||||||||||||||||||
| * Returns true if the client is configured to use a static access token. | ||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||
| * @returns True if the client is configured to use a static access token. | ||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||
| public isStaticAccessToken(): boolean { | ||||||||||||||||||||||||||||||
| return !!this.staticAccessToken; | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| protected authHeaders(): string | Promise<string> { | ||||||||||||||||||||||||||||||
| if (this.staticAccessToken) { | ||||||||||||||||||||||||||||||
| return `Bearer ${this.staticAccessToken}`; | ||||||||||||||||||||||||||||||
|
|
@@ -281,31 +298,68 @@ | |||||||||||||||||||||||||||||
| as, | ||||||||||||||||||||||||||||||
| } = this.oauthClient | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| let attempts = 0; | ||||||||||||||||||||||||||||||
| const maxAttempts = 2; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| while (!this.oauthAccessToken || this.oauthAccessToken.expiresAt - Date.now() < 1000) { | ||||||||||||||||||||||||||||||
| if (attempts > maxAttempts) { | ||||||||||||||||||||||||||||||
| throw new Error("ran out of attempts trying to retrieve oauth access token"); | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| if (attempts > 0) { | ||||||||||||||||||||||||||||||
| // Wait for a short duration before retrying to avoid rapid retries | ||||||||||||||||||||||||||||||
| await new Promise((resolve) => setTimeout(resolve, 100)); | ||||||||||||||||||||||||||||||
| for (let attempts = 0; attempts <= maxAttempts; attempts++) { | ||||||||||||||||||||||||||||||
|
Comment on lines
301
to
+304
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Clarify the retry attempt count. The variable is named Either rename the variable or adjust the loop condition: - const maxAttempts = 2;
+ const maxAttempts = 3; // Total attempts including the initial oneOr: - for (let attempts = 0; attempts <= maxAttempts; attempts++) {
+ for (let attempts = 0; attempts < maxAttempts; attempts++) {📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||
| if (attempts > 0) { | ||||||||||||||||||||||||||||||
| // Wait for a short duration before retrying to avoid rapid retries | ||||||||||||||||||||||||||||||
| await new Promise((resolve) => setTimeout(resolve, 100)); | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| const parameters = new URLSearchParams(); | ||||||||||||||||||||||||||||||
| if (this.scope && this.scope.length > 0) { | ||||||||||||||||||||||||||||||
| parameters.set("scope", this.scope.join(" ")); | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| parameters.set("project_id", this.projectId); | ||||||||||||||||||||||||||||||
| parameters.set("environment", this.environment); | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||
| const response = await oauth.clientCredentialsGrantRequest(as, client, clientAuth, parameters); | ||||||||||||||||||||||||||||||
| const oauthTokenResponse = await oauth.processClientCredentialsResponse(as, client, response); | ||||||||||||||||||||||||||||||
| this.oauthAccessToken = { | ||||||||||||||||||||||||||||||
| token: oauthTokenResponse.access_token, | ||||||||||||||||||||||||||||||
| expiresAt: Date.now() + (oauthTokenResponse.expires_in || 0) * 1000, | ||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||
| break; // Successfully got token, exit retry loop | ||||||||||||||||||||||||||||||
| } catch (e) { | ||||||||||||||||||||||||||||||
| // Extract error details from OAuth response | ||||||||||||||||||||||||||||||
| let errorMessage = "OAuth token request failed"; | ||||||||||||||||||||||||||||||
| let wwwAuthenticate: string | undefined; | ||||||||||||||||||||||||||||||
| let statusCode: number | undefined; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| if (e instanceof Error) { | ||||||||||||||||||||||||||||||
| errorMessage = e.message; | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| // Check if the error contains response information | ||||||||||||||||||||||||||||||
| if (e && typeof e === 'object' && 'response' in e) { | ||||||||||||||||||||||||||||||
|
Check failure on line 336 in packages/sdk/src/server/index.ts
|
||||||||||||||||||||||||||||||
| const errorResponse = (e as any).response; | ||||||||||||||||||||||||||||||
| if (errorResponse) { | ||||||||||||||||||||||||||||||
| statusCode = errorResponse.status; | ||||||||||||||||||||||||||||||
| wwwAuthenticate = errorResponse.headers?.get?.('www-authenticate') || | ||||||||||||||||||||||||||||||
|
Check failure on line 340 in packages/sdk/src/server/index.ts
|
||||||||||||||||||||||||||||||
| errorResponse.headers?.['www-authenticate']; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| // Create more specific error message based on status code | ||||||||||||||||||||||||||||||
| if (statusCode === 401) { | ||||||||||||||||||||||||||||||
| errorMessage = `OAuth authentication failed (401 Unauthorized)${wwwAuthenticate ? `: ${wwwAuthenticate}` : ''}`; | ||||||||||||||||||||||||||||||
| } else if (statusCode === 400) { | ||||||||||||||||||||||||||||||
| errorMessage = "OAuth request invalid (400 Bad Request) - check client credentials"; | ||||||||||||||||||||||||||||||
| } else if (statusCode) { | ||||||||||||||||||||||||||||||
| errorMessage = `OAuth request failed with status ${statusCode}`; | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| // If this is the last attempt, throw a detailed error | ||||||||||||||||||||||||||||||
| if (attempts >= maxAttempts) { | ||||||||||||||||||||||||||||||
| const error = new Error(errorMessage); | ||||||||||||||||||||||||||||||
| (error as any).statusCode = statusCode; | ||||||||||||||||||||||||||||||
| (error as any).wwwAuthenticate = wwwAuthenticate; | ||||||||||||||||||||||||||||||
| throw error; | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| const parameters = new URLSearchParams(); | ||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||
| const response = await oauth.clientCredentialsGrantRequest(as, client, clientAuth, parameters); | ||||||||||||||||||||||||||||||
| const oauthTokenResponse = await oauth.processClientCredentialsResponse(as, client, response); | ||||||||||||||||||||||||||||||
| this.oauthAccessToken = { | ||||||||||||||||||||||||||||||
| token: oauthTokenResponse.access_token, | ||||||||||||||||||||||||||||||
| expiresAt: Date.now() + (oauthTokenResponse.expires_in || 0) * 1000, | ||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||
| } catch { | ||||||||||||||||||||||||||||||
| // pass | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| attempts++; | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| return this.oauthAccessToken.token; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.