Skip to content

[PECO-728] Add OAuth support - #147

Merged
kravets-levko merged 9 commits into
mainfrom
PECO-728-oauth-support
Jun 28, 2023
Merged

[PECO-728] Add OAuth support#147
kravets-levko merged 9 commits into
mainfrom
PECO-728-oauth-support

Conversation

@kravets-levko

@kravets-levkokravets-levko commented Jun 8, 2023

Copy link
Copy Markdown
Contributor

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)

Signed-off-by: Levko Kravets <levko.ne@gmail.com>
@kravets-levko
kravets-levkoforce-pushed the PECO-728-oauth-support branch from e600b7b to 9bf2327CompareJune 8, 2023 14:22
…lAuthentication
Signed-off-by: Levko Kravets <levko.ne@gmail.com>
Signed-off-by: Levko Kravets <levko.ne@gmail.com>
@kravets-levko
kravets-levkoforce-pushed the PECO-728-oauth-support branch from 5effef8 to 7c15742CompareJune 21, 2023 06:53
Signed-off-by: Levko Kravets <levko.ne@gmail.com>
Signed-off-by: Levko Kravets <levko.ne@gmail.com>
Signed-off-by: Levko Kravets <levko.ne@gmail.com>
Signed-off-by: Levko Kravets <levko.ne@gmail.com>
Signed-off-by: Levko Kravets <levko.ne@gmail.com>
@codecov-commenter

Copy link
Copy Markdown

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 FilesCoverage Δ
...ib/connection/auth/DatabricksOAuth/OAuthManager.ts89.74% <89.74%> (ø)
...nnection/auth/DatabricksOAuth/AuthorizationCode.ts97.10% <97.10%> (ø)
lib/DBSQLClient.ts97.18% <100.00%> (+0.30%)⬆️
lib/connection/auth/DatabricksOAuth/OAuthToken.ts100.00% <100.00%> (ø)
lib/connection/auth/DatabricksOAuth/index.ts100.00% <100.00%> (ø)

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

@nithinkdbnithinkdb left a comment

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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?

@kravets-levkokravets-levkoJun 28, 2023

Copy link
Copy Markdown
ContributorAuthor

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
Copy Markdown
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
Copy Markdown
ContributorAuthor

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 mainJun 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 <levko.ne@gmail.com>
* Cleanup DBSQLClient code; remove redundant and no longer needed NoSaslAuthentication
Signed-off-by: Levko Kravets <levko.ne@gmail.com>
* DBSQLClient: options for auth types
Signed-off-by: Levko Kravets <levko.ne@gmail.com>
* Tests
Signed-off-by: Levko Kravets <levko.ne@gmail.com>
* Tests
Signed-off-by: Levko Kravets <levko.ne@gmail.com>
* Fix: move comment to appropriate place
Signed-off-by: Levko Kravets <levko.ne@gmail.com>
* Improve tests
Signed-off-by: Levko Kravets <levko.ne@gmail.com>
* Use proper client ID; improve callback handling
Signed-off-by: Levko Kravets <levko.ne@gmail.com>
---------
Signed-off-by: Levko Kravets <levko.ne@gmail.com>
Signed-off-by: nithinkdb <nithin.krishnamurthi@databricks.com>
Sign up for freeto 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

@kravets-levko@codecov-commenter@nithinkdb