Skip to content

Commit 21e6676

Browse files
girardajosephkmhjoeykmhteallarson
committed
chore: webapp calls the embedded-specific consent url endpoint when running within the embedded context (#16130)
Co-authored-by: josephkmh <[email protected]> Co-authored-by: Joey Marshment-Howell <[email protected]> Co-authored-by: teallarson <[email protected]>
1 parent aba0e0a commit 21e6676

File tree

4 files changed

+26
-5
lines changed

4 files changed

+26
-5
lines changed

airbyte-webapp/STYLEGUIDE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ This serves as a living document regarding conventions we have agreed upon as a
1414

1515
The following recommendations are all in service to two broader principles:
1616

17-
- compoonents should be reusable in as many different contexts as possible without changing their "internal" CSS
17+
- components should be reusable in as many different contexts as possible without changing their "internal" CSS
1818
- the impact on layout and spacing of adding any component to an existing page should be predictable
1919

2020
If naively following the recommendations ever undermines those principles, by all means

airbyte-webapp/src/core/api/hooks/connectorOAuth.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
completeDestinationOAuth,
55
completeSourceOAuth,
66
getDestinationOAuthConsent,
7+
getEmbeddedSourceOAuthConsent,
78
getSourceOAuthConsent,
89
revokeSourceOAuthTokens,
910
getConnectorBuilderProjectOAuthConsent,
@@ -13,6 +14,7 @@ import {
1314
CompleteDestinationOAuthRequest,
1415
CompleteSourceOauthRequest,
1516
DestinationOauthConsentRequest,
17+
EmbeddedSourceOauthConsentRequest,
1618
RevokeSourceOauthTokensRequest,
1719
SourceOauthConsentRequest,
1820
BuilderProjectOauthConsentRequest,
@@ -28,6 +30,9 @@ export function useConsentUrls() {
2830
getSourceConsentUrl(request: SourceOauthConsentRequest) {
2931
return getSourceOAuthConsent(request, requestOptions);
3032
},
33+
getEmbeddedSourceConsentUrl(request: EmbeddedSourceOauthConsentRequest) {
34+
return getEmbeddedSourceOAuthConsent(request, requestOptions);
35+
},
3136
getDestinationConsentUrl(request: DestinationOauthConsentRequest) {
3237
return getDestinationOAuthConsent(request, requestOptions);
3338
},

airbyte-webapp/src/hooks/services/useConnectorAuth.tsx

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
CompleteOAuthResponse,
1313
CompleteOAuthResponseAuthPayload,
1414
DestinationOauthConsentRequest,
15+
EmbeddedSourceOauthConsentRequest,
1516
SourceOauthConsentRequest,
1617
BuilderProjectOauthConsentRequest,
1718
CompleteConnectorBuilderProjectOauthRequest,
@@ -71,31 +72,43 @@ export function useConnectorAuth(): {
7172
connector: ConnectorDefinitionSpecificationRead,
7273
oAuthInputConfiguration: Record<string, unknown>
7374
) => Promise<{
74-
payload: SourceOauthConsentRequest | DestinationOauthConsentRequest;
75+
payload: SourceOauthConsentRequest | EmbeddedSourceOauthConsentRequest | DestinationOauthConsentRequest;
7576
consentUrl: string;
7677
}>;
7778
completeOauthRequest: (
78-
params: SourceOauthConsentRequest | DestinationOauthConsentRequest,
79+
params: SourceOauthConsentRequest | EmbeddedSourceOauthConsentRequest | DestinationOauthConsentRequest,
7980
queryParams: Record<string, unknown>
8081
) => Promise<CompleteOAuthResponse>;
8182
} {
8283
const { formatMessage } = useIntl();
8384
const workspaceId = useCurrentWorkspaceId();
84-
const { getDestinationConsentUrl, getSourceConsentUrl } = useConsentUrls();
85+
const { getDestinationConsentUrl, getSourceConsentUrl, getEmbeddedSourceConsentUrl } = useConsentUrls();
8586
const { completeDestinationOAuth, completeSourceOAuth } = useCompleteOAuth();
8687
const notificationService = useNotificationService();
8788
const { connectorId } = useConnectorForm();
89+
const isEmbedded = useIsAirbyteEmbeddedContext();
8890

8991
return {
9092
getConsentUrl: async (
9193
connector: ConnectorDefinitionSpecificationRead,
9294
oAuthInputConfiguration: Record<string, unknown>
9395
): Promise<{
94-
payload: SourceOauthConsentRequest | DestinationOauthConsentRequest;
96+
payload: SourceOauthConsentRequest | EmbeddedSourceOauthConsentRequest | DestinationOauthConsentRequest;
9597
consentUrl: string;
9698
}> => {
9799
try {
98100
if (isSourceDefinitionSpecification(connector)) {
101+
if (isEmbedded) {
102+
const payload: EmbeddedSourceOauthConsentRequest = {
103+
workspaceId,
104+
sourceDefinitionId: ConnectorSpecification.id(connector),
105+
redirectUrl: OAUTH_REDIRECT_URL,
106+
sourceId: connectorId,
107+
};
108+
const response = await getEmbeddedSourceConsentUrl(payload);
109+
110+
return { consentUrl: response.consentUrl, payload };
111+
}
99112
const payload: SourceOauthConsentRequest = {
100113
workspaceId,
101114
sourceDefinitionId: ConnectorSpecification.id(connector),

airbyte-webapp/src/views/Connector/ConnectorForm/ConnectorForm.test.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* eslint-disable @typescript-eslint/no-non-null-assertion */
2+
23
import { getByTestId, screen, waitFor, getByRole, fireEvent } from "@testing-library/react";
34
import userEvent from "@testing-library/user-event";
45
import { BroadcastChannel } from "broadcast-channel";
@@ -11,6 +12,7 @@ import { useCompleteOAuth } from "core/api";
1112
import { DestinationDefinitionSpecificationRead, OAuthConsentRead } from "core/api/types/AirbyteClient";
1213
import { ConnectorDefinition, ConnectorDefinitionSpecificationRead } from "core/domain/connector";
1314
import { AirbyteJSONSchema } from "core/jsonSchema/types";
15+
import * as EmbeddedContext from "core/services/embedded";
1416
import { FeatureItem } from "core/services/features";
1517
import { ConnectorForm } from "views/Connector/ConnectorForm";
1618

@@ -1024,6 +1026,7 @@ describe("Connector form", () => {
10241026
});
10251027
},
10261028
});
1029+
jest.spyOn(EmbeddedContext, "useIsAirbyteEmbeddedContext").mockReturnValue(false);
10271030
const container = await renderNewOAuthForm();
10281031

10291032
await executeOAuthFlow(container);

0 commit comments

Comments
 (0)