Skip to content

[PECO-728] Add OAuth support #147

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

Merged
merged 9 commits into from
Jun 28, 2023
Merged

[PECO-728] Add OAuth support #147

merged 9 commits into from
Jun 28, 2023

Conversation

kravets-levko
Copy link
Contributor

@kravets-levko kravets-levko commented Jun 8, 2023

PECO-728 Add OAuth support

Related to (and partially based on) databricks/databricks-sql-python#15

  • Implement OAuth authentication method
  • Add tests
  • Configure a dedicated client app for Nodejs (instead of using PySQL's one)

@databricks databricks deleted a comment from codecov-commenter Jun 8, 2023
@kravets-levko kravets-levko force-pushed the PECO-728-oauth-support branch from 26f2ffe to e600b7b Compare June 8, 2023 13:59
@databricks databricks deleted a comment from codecov-commenter Jun 8, 2023
Signed-off-by: Levko Kravets <[email protected]>
@kravets-levko kravets-levko force-pushed the PECO-728-oauth-support branch from e600b7b to 9bf2327 Compare June 8, 2023 14:22
@databricks databricks deleted a comment from codecov-commenter Jun 13, 2023
@kravets-levko kravets-levko force-pushed the PECO-728-oauth-support branch from 5effef8 to 7c15742 Compare June 21, 2023 06:53
Signed-off-by: Levko Kravets <[email protected]>
Signed-off-by: Levko Kravets <[email protected]>
@databricks databricks deleted a comment from codecov-commenter Jun 22, 2023
@codecov-commenter
Copy link

Codecov Report

Patch coverage: 95.91% and project coverage change: -0.07 ⚠️

Comparison is base (0a2bdb4) 96.28% compared to head (2edbb66) 96.21%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #147      +/-   ##
==========================================
- Coverage   96.28%   96.21%   -0.07%     
==========================================
  Files          50       54       +4     
  Lines         808      952     +144     
  Branches      134      160      +26     
==========================================
+ Hits          778      916     +138     
- Misses          9       10       +1     
- Partials       21       26       +5     
Impacted Files Coverage Δ
...ib/connection/auth/DatabricksOAuth/OAuthManager.ts 89.74% <89.74%> (ø)
...nnection/auth/DatabricksOAuth/AuthorizationCode.ts 97.10% <97.10%> (ø)
lib/DBSQLClient.ts 97.18% <100.00%> (+0.30%) ⬆️
lib/connection/auth/DatabricksOAuth/OAuthToken.ts 100.00% <100.00%> (ø)
lib/connection/auth/DatabricksOAuth/index.ts 100.00% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Contributor

@nithinkdb nithinkdb left a comment

Choose a reason for hiding this comment

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

Overall looks good, I just have a couple questions

port: number,
requestHandler: (req: IncomingMessage, res: ServerResponse) => void,
): Promise<Server> {
const server = http.createServer(requestHandler);
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this ever create issues of trying to send an https request from an http server?

Copy link
Contributor Author

@kravets-levko kravets-levko Jun 28, 2023

Choose a reason for hiding this comment

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

OAuth app we use is configured to allow http only. But it's not an issue, because we receive only authorization token via callback url, and then use that auth token + verifier string in another request to OAuth endpoint to obtain access and refresh tokens. All OAuth endpoints use https. So even is anyone will intercept auth code - it's basically useles without verifier which is not exposed anywhere

}

return new Promise((resolve, reject) => {
const errorListener = (error: Error) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

This syntax is really strange to me, where did you get this? The errorListener invokes server off with itself?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here (and similarly in startServer) I just "promisify" server methods. Node's http server has event-based API, but since all our code is Promise-based, I wrapped server creation and stopping routines. How it works: first I create an error handler function and attach it to server's error event. Then I invoke a method I need, and if it was successful - I remove that error listener (therefore I store it in variable), and resolve promise. If called method emits an error - my error handler catches it, removes itself and rejects promise. Error handler here is needed only once to handle a single error, therefore I keep a function to be able to unregister it once it's no longer needed

@kravets-levko kravets-levko merged commit 71d45a2 into main Jun 28, 2023
@kravets-levko kravets-levko deleted the PECO-728-oauth-support branch June 28, 2023 15:39
nithinkdb pushed a commit to nithinkdb/databricks-sql-nodejs that referenced this pull request Aug 21, 2023
* [PECO-728] Add OAuth support

Signed-off-by: Levko Kravets <[email protected]>

* Cleanup DBSQLClient code; remove redundant and no longer needed NoSaslAuthentication

Signed-off-by: Levko Kravets <[email protected]>

* DBSQLClient: options for auth types

Signed-off-by: Levko Kravets <[email protected]>

* Tests

Signed-off-by: Levko Kravets <[email protected]>

* Tests

Signed-off-by: Levko Kravets <[email protected]>

* Fix: move comment to appropriate place

Signed-off-by: Levko Kravets <[email protected]>

* Improve tests

Signed-off-by: Levko Kravets <[email protected]>

* Use proper client ID; improve callback handling

Signed-off-by: Levko Kravets <[email protected]>

---------

Signed-off-by: Levko Kravets <[email protected]>
Signed-off-by: nithinkdb <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants