-
Notifications
You must be signed in to change notification settings - Fork 432
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
Feature/add connection token #2671
base: master
Are you sure you want to change the base?
Conversation
Warning Rate limit exceeded@komyg has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 11 minutes and 28 seconds before requesting another review. How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. WalkthroughThe recent changes involve updates to the database schema, authentication processes, and connection management across multiple components. Key modifications include the addition of a Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant Frontend
participant OAuthController
participant ConnectionService
User->>Frontend: Initiate Connection Creation
Frontend->>OAuthController: Request Authentication
OAuthController->>ConnectionService: Check for connection_id
alt connection_id exists
ConnectionService-->>OAuthController: Use existing connection_id
else connection_id missing
ConnectionService-->>OAuthController: Generate connectionToken
end
OAuthController-->>Frontend: Return Authentication Result
Frontend-->>User: Display Success/Error Message
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Outside diff range, codebase verification and nitpick comments (1)
packages/shared/lib/services/connection.service.ts (1)
93-118
: Potential Issue withconnectionToken
HandlingThe current implementation correctly handles the absence of
connectionToken
by checking for existing connections and updating them. However, there is no evidence of logic to handle the case whenconnectionToken
is provided, which suggests that the feature might not be fully implemented. Please review the code to ensure that new connections are inserted withconnectionToken
when it is provided.
- Ensure that there is logic outside the
if (!connectionToken)
block to handle the insertion of new connections withconnectionToken
.Analysis chain
Verify the handling of
connectionToken
in the new conditional block.Ensure that the new conditional block correctly handles the presence and absence of
connectionToken
:
- If
connectionToken
is not provided, the method should proceed with the existing logic to check if a connection exists and update or insert it accordingly.- If
connectionToken
is provided, the method should skip the existing logic and directly insert a new connection with theconnectionToken
included in the encrypted connection object.Run the following script to verify the handling of
connectionToken
:Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the handling of `connectionToken` in the `upsertConnection` method. # Test 1: Search for the conditional block that checks the presence of `connectionToken`. # Expect: The conditional block should be present. ast-grep --lang typescript --pattern $'if (!connectionToken) { $$$ }' # Test 2: Search for the existing logic to check if a connection exists and update or insert it accordingly within the conditional block. # Expect: The existing logic should be present within the conditional block. ast-grep --lang typescript --pattern $'if (!connectionToken) { $$$ const storedConnection = await this.checkIfConnectionExists($$$); $$$ if (storedConnection) { $$$ const encryptedConnection = encryptionManager.encryptConnection({ $$$ }); $$$ const connection = await db.knex .from<StoredConnection>(\`_nango_connections\`) .where({ id: storedConnection.id!, deleted: false }) .update(encryptedConnection) .returning(\'*\'); $$$ } }' # Test 3: Search for the logic to insert a new connection with `connectionToken` outside the conditional block. # Expect: The logic to insert a new connection with `connectionToken` should be present outside the conditional block. ast-grep --lang typescript --pattern $'const connection = await db.knex .from<StoredConnection>(\`_nango_connections\`) .insert( encryptionManager.encryptConnection({ $$$ connection_token: connectionToken, $$$ }) ) .returning(\'*\');'Length of output: 3614
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (9)
- packages/database/lib/migrations/20240903153801_create_connection_token.cjs (1 hunks)
- packages/frontend/lib/index.ts (5 hunks)
- packages/server/lib/controllers/environment.controller.ts (1 hunks)
- packages/server/lib/controllers/oauth.controller.ts (8 hunks)
- packages/shared/lib/models/Auth.ts (1 hunks)
- packages/shared/lib/models/Connection.ts (3 hunks)
- packages/shared/lib/services/connection.service.ts (3 hunks)
- packages/webapp/src/pages/Connection/Create.tsx (3 hunks)
- packages/webapp/src/utils/api.tsx (1 hunks)
Additional comments not posted (24)
packages/database/lib/migrations/20240903153801_create_connection_token.cjs (1)
7-12
: Verify the impact of making theconnection_id
column nullable and consider using Knex's schema builder methods.Please consider the following:
- Verify the impact of making the
connection_id
column nullable:
- Ensure that the existing code handles nullable
connection_id
values correctly.- If the
connection_id
column is used as a foreign key in other tables, ensure that those tables allow null values for this column.Run the following script to verify the impact:
- Consider using Knex's schema builder methods for better portability across different databases. For example:
await knex.schema.alterTable('_nango_connections', (table) => { table.uuid(CONNECTION_TOKEN_COLUMN).unique(); table.uuid(CONNECTION_ID_COLUMN).nullable().alter(); });packages/shared/lib/models/Connection.ts (3)
12-12
: LGTM!The addition of the optional
connection_token
property to theBaseConnection
interface looks good. It enhances the flexibility of the interface without breaking existing code.
68-68
: LGTM!The addition of the optional
connection_token
property to theNangoConnection
interface looks good. It enhances the flexibility of the interface without breaking existing code.
83-83
: LGTM!The addition of the optional
connection_token
property to theConnectionList
interface looks good. It enhances the flexibility of the interface without breaking existing code.packages/shared/lib/models/Auth.ts (1)
24-24
: LGTM!The addition of the optional
connectionToken
property to theOAuthSession
interface is a valid change. The property is correctly marked as optional and its type is appropriately defined asstring | undefined
.packages/server/lib/controllers/environment.controller.ts (1)
Line range hint
80-95
: Verify the handling ofundefined
connectionId
in thehmacService.digest
method.The conditional check for
connectionId
has been removed. Ensure that thehmacService.digest
method handles the case whenconnectionId
isundefined
to avoid any potential issues.Run the following script to verify the handling of
undefined
connectionId
:packages/webapp/src/utils/api.tsx (1)
665-669
: LGTM!The changes to the
useGetHmacAPI
function look good:
- Making the
connectionId
parameter optional allows for more flexible usage of the function.- The updated URL construction logic correctly handles the presence or absence of
connectionId
, improving maintainability and reducing potential errors.These modifications align with the alterations mentioned in the summary.
packages/frontend/lib/index.ts (6)
29-33
: LGTM!The new interface
AuthenticationResult
is well-defined and follows the existing coding conventions.
39-47
: LGTM!The new type
AuthConfigOptions
is correctly defined as a union type and includes all the relevant types.
128-149
: LGTM!The new method
authentication
is well-implemented and follows the existing coding conventions. The validation checks and URL construction are handled appropriately.
159-159
: LGTM!The changes to the
auth
method are minimal and do not affect its functionality. The deprecation notice is appropriate.
185-209
: LGTM!The changes to the
callAuth
method correctly handle bothAuthResult
andAuthenticationResult
. The updatedsuccessHandler
function and promise resolution logic are implemented appropriately.
484-488
: LGTM!Making the
connectionId
parameter optional in thetoQueryString
method is consistent with the changes made to theauth
method and provides flexibility.packages/server/lib/controllers/oauth.controller.ts (4)
56-60
: LGTM!The changes ensure that a valid connection identifier (
connectionId
) is always available by using theconnection_id
from the request query if it exists, otherwise falling back to a newly generatedconnectionToken
.
109-112
: LGTM!The HMAC verification process is updated to conditionally include
connectionId
only if it was received from the request, allowing for a more flexible verification.
Line range hint
831-931
: LGTM!The
connectionToken
is now included in various logging statements, ensuring that it is consistently tracked throughout the OAuth flow. This may facilitate better debugging and monitoring of connection-related activities.
Line range hint
956-1065
: LGTM!The
connectionToken
is included in the logging statement after receiving the token response and passed to theconnectionService.upsertConnection
method, ensuring that it is consistently tracked and associated with the connection.packages/webapp/src/pages/Connection/Create.tsx (4)
33-33
: LGTM!The changes to the
connectionId
state variable look good:
- Changing the type to
string | null
allows for cases where the connection ID may not be available immediately.- Initializing it as
null
is a best practice when the initial value is unknown.These changes enhance the component's flexibility in handling different connection states.
202-220
: LGTM!The added code block to handle missing
connection_id
looks good:
- It enhances the component's functionality by initiating the authentication process when
connection_id
is not provided.- The
nango.authentication
method is called with the necessary parameters to handle the authentication flow.- Showing success and error messages improves the user experience by providing appropriate feedback.
- Navigating to the connections page on successful authentication ensures a smooth user flow.
These changes make the component more robust in handling different scenarios during the connection creation process.
204-210
: LGTM!The parameters passed to the
nango.authentication
method look good:
- The
integration_unique_key
is correctly obtained from the form data.- The
user_scope
is obtained from theselectedScopes
state variable.- The
params
are obtained from theconnectionConfigParams
state variable or an empty object.- The
authorization_params
are obtained from theauthorizationParams
state variable or an empty object.- The
hmac
is obtained from thehmacDigest
state variable or an empty string.- The
credentials
are obtained based on theauthMode
and the corresponding state variables.These parameters ensure that the necessary data is passed to the authentication method for proper handling of the connection creation process.
211-219
: LGTM!The handling of success and error scenarios after the authentication process looks good:
- On successful authentication:
- A success toast message is shown to provide visual feedback to the user.
- An analytics event is tracked to monitor and analyze user actions.
- The data is mutated to ensure the UI reflects the updated state.
- The user is navigated to the connections page, providing a logical flow after the successful connection creation.
- If an error occurs during authentication:
- An error message is set based on the error type to provide meaningful feedback to the user.
These changes ensure proper handling of the authentication outcome and enhance the user experience by providing appropriate feedback and navigation.
packages/shared/lib/services/connection.service.ts (3)
73-73
: LGTM!The new optional
connectionToken
parameter in the method signature looks good.
83-83
: LGTM!The new optional
connectionToken
parameter in the method signature looks good.
126-126
: LGTM!The inclusion of
connectionToken
in the encrypted connection object when inserting a new connection looks good.
exports.down = async function (knex) { | ||
await knex.schema.raw(`ALTER TABLE "_nango_connections" DROP COLUMN "${CONNECTION_TOKEN_COLUMN}"`); | ||
await knex.schema.raw(`ALTER TABLE "_nango_connections" ALTER COLUMN "${CONNECTION_ID_COLUMN}" SET NOT NULL;`); | ||
await knex.schema.raw(`ALTER TABLE "_nango_oauth_sessions" DROP COLUMN "${CONNECTION_TOKEN_COLUMN}"`); | ||
await knex.schema.raw(`ALTER TABLE "_nango_oauth_sessions" ALTER COLUMN "${CONNECTION_ID_COLUMN}" SET NOT NULL;`); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using Knex's schema builder methods for better portability.
Similar to the up
function, consider using Knex's schema builder methods for better portability across different databases. For example:
await knex.schema.alterTable('_nango_connections', (table) => {
table.dropColumn(CONNECTION_TOKEN_COLUMN);
table.uuid(CONNECTION_ID_COLUMN).notNullable().alter();
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (4)
- packages/frontend/lib/index.ts (8 hunks)
- packages/server/lib/clients/publisher.client.ts (1 hunks)
- packages/server/lib/controllers/oauth.controller.ts (9 hunks)
- packages/webapp/src/pages/Connection/Create.tsx (4 hunks)
Files skipped from review as they are similar to previous changes (3)
- packages/frontend/lib/index.ts
- packages/server/lib/controllers/oauth.controller.ts
- packages/webapp/src/pages/Connection/Create.tsx
Additional comments not posted (1)
packages/server/lib/clients/publisher.client.ts (1)
208-215
: LGTM!The code changes to the
notifySuccess
method are approved:
- The method signature has been correctly updated to include an optional
connectionToken
parameter.- The
connectionToken
is correctly included in the JSON payload sent to the client.- The changes are consistent with the AI-generated summary and do not introduce any issues or inconsistencies.
Also applies to: 221-221
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (3)
- .vscode/launch.json (1 hunks)
- docker-compose.yaml (1 hunks)
- packages/shared/lib/services/connection.service.ts (4 hunks)
Files skipped from review due to trivial changes (2)
- .vscode/launch.json
- docker-compose.yaml
Files skipped from review as they are similar to previous changes (1)
- packages/shared/lib/services/connection.service.ts
445840b
to
69ec8f3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (17)
- .vscode/launch.json (1 hunks)
- docker-compose.yaml (1 hunks)
- docs-v2/integrate/guides/advanced/secure-frontend-sdk.mdx (2 hunks)
- docs-v2/integrate/guides/authorize-an-api.mdx (1 hunks)
- docs-v2/integrate/overview.mdx (1 hunks)
- docs-v2/introduction.mdx (2 hunks)
- docs-v2/reference/sdks/frontend.mdx (4 hunks)
- packages/database/lib/migrations/20240903153801_create_connection_token.cjs (1 hunks)
- packages/frontend/lib/index.ts (8 hunks)
- packages/server/lib/clients/publisher.client.ts (1 hunks)
- packages/server/lib/controllers/environment.controller.ts (1 hunks)
- packages/server/lib/controllers/oauth.controller.ts (9 hunks)
- packages/shared/lib/models/Auth.ts (1 hunks)
- packages/shared/lib/models/Connection.ts (3 hunks)
- packages/shared/lib/services/connection.service.ts (4 hunks)
- packages/webapp/src/pages/Connection/Create.tsx (5 hunks)
- packages/webapp/src/utils/api.tsx (1 hunks)
Files skipped from review due to trivial changes (4)
- .vscode/launch.json
- docker-compose.yaml
- docs-v2/introduction.mdx
- packages/database/lib/migrations/20240903153801_create_connection_token.cjs
Files skipped from review as they are similar to previous changes (7)
- packages/server/lib/controllers/environment.controller.ts
- packages/server/lib/controllers/oauth.controller.ts
- packages/shared/lib/models/Auth.ts
- packages/shared/lib/models/Connection.ts
- packages/shared/lib/services/connection.service.ts
- packages/webapp/src/pages/Connection/Create.tsx
- packages/webapp/src/utils/api.tsx
Additional comments not posted (22)
docs-v2/integrate/overview.mdx (2)
23-23
: LGTM!The code change is consistent with the AI-generated summary. The
connectionId
variable is no longer being passed to thenango.auth
function.
27-27
: LGTM!The code change is consistent with the AI-generated summary. The
connectionToken
obtained from theresult
of the authentication process is now being passed to thesaveToDatabase
function.docs-v2/integrate/guides/advanced/secure-frontend-sdk.mdx (2)
11-11
: LGTM!The code changes are approved.
151-154
: LGTM!The code changes are approved.
docs-v2/integrate/guides/authorize-an-api.mdx (1)
82-82
: LGTM!The change in the method name from
nango.auth()
tonango.authentication()
improves clarity and aligns with the alterations list.packages/server/lib/clients/publisher.client.ts (1)
208-215
: LGTM!The code changes are approved for the following reasons:
- The
notifySuccess
method signature has been correctly updated to include an optionalconnectionToken
parameter.- The
connectionToken
is correctly included in the JSON payload.- The control flow remains intact.
- The method now supports a broader range of use cases by accommodating the new parameter.
Also applies to: 221-221
docs-v2/reference/sdks/frontend.mdx (9)
27-27
: LGTM!The code segment is approved.
52-54
: LGTM!The code segment is approved.
59-63
: LGTM!The code segment is approved.
64-117
: LGTM!The code segment is approved.
119-148
: LGTM!The code segment is approved.
150-151
: LGTM!The code segment is approved.
208-208
: LGTM!The code segment is approved.
212-212
: LGTM!The code segment is approved.
271-271
: LGTM!The code segment is approved.
packages/frontend/lib/index.ts (7)
29-33
: LGTM!The new
AuthenticationResult
interface is well-defined and serves the purpose of encapsulating the results of the authentication process.
39-47
: LGTM!The new
AuthConfigOptions
type alias consolidates various credential types into a single type union, which improves code readability and maintainability.
128-149
: LGTM!The new
authentication
method is well-structured and handles the authentication process effectively. The validation checks ensure that only standard OAuth2 flows are supported, and the error handling is appropriate.
Line range hint
159-183
: LGTM!The changes to the
auth
method are consistent with the introduction of the newauthentication
method. The deprecation notice is helpful for guiding users towards the preferred authentication approach.
185-207
: LGTM!The changes to
callAuth
reflect the updates in the authentication flow and ensure compatibility with bothAuthResult
andAuthenticationResult
. The modified success handler handles the presence ofconnectionToken
appropriately.
Line range hint
486-537
: LGTM!Making the
connectionId
parameter optional intoQueryString
allows for greater flexibility in generating query strings. The changes are consistent with the rest of the codebase.
Line range hint
666-697
: LGTM!The changes to the
handleMessage
method in theAuthorizationModal
class are consistent with the updates in the authentication flow. The modified success handler signature aligns with the changes made in theNango
class.
69ec8f3
to
5f009f1
Compare
* @param options - Optional. Additional options for authorization | ||
* @returns A promise that resolves with the authorization result | ||
*/ | ||
public async authentication(providerConfigKey: string, options?: AuthConfigOptions): Promise<AuthenticationResult> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I would prefer a different nameauthenticate
perhaps?
Describe your changes
connection_token
column to the_nango_connections
table.connection_token
column to the_nango_oauth_sessions
table.authentication
method in the frontend SDK that does not require theconnectionId
and that returns the newconnectionToken
created by the backend.auth
method in the frontend SDK.create
component to call the newauthentication
method, that does not require aconnectionId
if noconnectionId
is set by the user.connectionToken
and save it.connectionToken
as the default value for theconnectionId
.ConnectionService
to save theconnectionToken
on the database.connectionId
.Issue ticket number and link
Checklist before requesting a review (skip if just adding/editing APIs & templates)
Summary by CodeRabbit
New Features
connection_token
feature in the database schema for enhanced connection management.Bug Fixes
Documentation
connectionToken
properties for better flexibility in OAuth sessions.