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

[PECO-909] Automatically renew oauth token when refresh token is available #156

Merged
merged 6 commits into from
Jul 31, 2023

Conversation

kravets-levko
Copy link
Contributor

@kravets-levko kravets-levko commented Jul 27, 2023

PECO-909

It is possible to auto-renew oauth access token if corresponding refresh token was provided. However, due to some limitations in library architecture, it wasn't possible to use that mechanism: after DBSQLClient.connect() call credentials were cached and not updated until re-connected. In this PR the following changes are suggestsed:

  • HiveDriver should not cache thrift client object and obtain it before running each operation. This allows to provide a new client if needed;
  • since the thrift library does not provide any API to just update client options, DBSQLClient will re-create thrift client (and connection) when needed. Turns out that this is safe and almost does not add much overhead (especially considering that token refresh does not happen very often).
    • auth logic is decoupled from HttpConnection and moved to DBSQLClient so DBSQLClient can detect credentials change
    • each time when HiveDriver needs a client instance, DBSQLClient will request auth credentials, and if they have changed (e.g. oauth access token expired and was refreshed) - it will create a new thrift client.
    • since auth token now is not stored within thrift client options, DatabricksOAuth stores token on its own. The existing persistence mechanism was utilized for this purpose.
  • Update tests

This is quite a big change, but library's public interface and observed behavior won't change.

Probably review will be easier commit by commit.

@kravets-levko kravets-levko changed the title Automatically renew oauth token when refresh token is available [PECO-909] Automatically renew oauth token when refresh token is available Jul 27, 2023
Signed-off-by: Levko Kravets <[email protected]>
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.

LGTM, but think someone else should take a look.

@kravets-levko kravets-levko merged commit 3572889 into main Jul 31, 2023
3 checks passed
@kravets-levko kravets-levko deleted the check-auth-before-each-request branch July 31, 2023 14:29
nithinkdb pushed a commit to nithinkdb/databricks-sql-nodejs that referenced this pull request Aug 21, 2023
…lable (databricks#156)

* HiveDriver: obtain a thrift client before each request (allows to re-create client if needed)

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

* Move auth logic to DBSQLClient

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

* Remove redundant HttpTransport class

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

* Cache OAuth tokens in memory by default to avoid re-running OAuth flow on every request

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

* Re-create thrift client when auth credentials (e.g. oauth token) change

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

* Update tests

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.

2 participants