Skip to content
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

[nan-638] add in credentials override and scopes override #1906

Merged

Conversation

khaliqgant
Copy link
Member

Describe your changes

Allow a user to override oauth credentials and scopes. Show in the UI only for netsuite

Issue ticket number and link

NAN-638

Checklist before requesting a review (skip if just adding/editing APIs & templates)

  • I added tests, otherwise the reason is:
  • I added observability, otherwise the reason is:
  • I added analytics, otherwise the reason is:

Copy link

linear bot commented Mar 26, 2024

username: string;
password: string;
}

export interface ApiKeyCredentials {
[key: string]: string;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this going to break some things? Don't we have weird cases of API key auth where users need to pass in more fields?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just the webapp types so it won't break anything that a user is doing.

Copy link
Contributor

@bodinsamuel bodinsamuel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor comments, the code regarding auth is really hard to read but seems good

credentials: {
oauth_client_id: '${optionalOAuthClientId}',
oauth_client_secret: '${optionalOAuthClientSecret}'
}`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

display: it's missing a line break here (or in the snippet)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the display this is what I see which is expected
image

Can you clarify what the issue you're seeing is?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's a detail, } }) line 5

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah gotcha. Updated with 1eff44a:

image
image
image
image

packages/shared/lib/models/Auth.ts Outdated Show resolved Hide resolved
acc[key] = connectionConfig[key] as string;
}
return acc;
}, {});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe it's just me but I have hard time reading reducer, I don't really understand what's going on

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't mind reduce personally but it would be way more readable in typescript if the initial value was the first parameter instead of the last one after the function. Sometimes I have a hard time understanding language creators/maintainers.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have rather just done

delete connectionConfig.oauth_client_id;
delete connectionConfig.oauth_client_secret;

but eslint was yelling at me.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah yes I see, I think it's fair to disable some eslint errors when we don't find them relevant.
And if it's often the case, it's always good to revisit the list of activated rules 👌🏻

@@ -99,9 +99,14 @@ export default class Nango {
public auth(
providerConfigKey: string,
connectionId: string,
options?: (ConnectionConfig | BasicApiCredentials | ApiKeyCredentials | AppStoreCredentials) & AuthOptions
options?: (ConnectionConfig | OptionalOAuthCredentials | BasicApiCredentials | ApiKeyCredentials | AppStoreCredentials) & AuthOptions
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about OverrideOAuthCredentials instead, to make it clear they would override the integration ones

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opted for OAuthCredentialsOverride

const credentials = connectionConfig.credentials;
if ('oauth_client_id' in credentials && 'oauth_client_secret' in credentials) {
query.push(`credentials[oauth_client_id]=${credentials.oauth_client_id}`);
query.push(`credentials[oauth_client_secret]=${credentials.oauth_client_secret}`);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here what about making it clearer with override_oauth_client_id and override_oauth_client_secret keys?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think this is necessary here if the interface is OAuthCredentialsOverride as this is just what we push to our server so it is just an internal name

acc[key] = connectionConfig[key] as string;
}
return acc;
}, {});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't mind reduce personally but it would be way more readable in typescript if the initial value was the first parameter instead of the last one after the function. Sometimes I have a hard time understanding language creators/maintainers.

@khaliqgant khaliqgant requested a review from TBonnin March 26, 2024 18:43
@khaliqgant khaliqgant merged commit 28e70dd into master Mar 26, 2024
18 checks passed
@khaliqgant khaliqgant deleted the khaliq/nan-638-handle-netsuite-per-connection-oauth-flow branch March 26, 2024 19:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants