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

feat: token refresh #818

Merged
merged 7 commits into from
Dec 15, 2023
Merged

feat: token refresh #818

merged 7 commits into from
Dec 15, 2023

Conversation

elboy3
Copy link
Contributor

@elboy3 elboy3 commented Dec 13, 2023

Shortcut Ticket

https://app.shortcut.com/galileo/story/10174/dq-api-client-token-refresh

Drew Inspiration from

We should have an automatic token refresh similar to LLM Monitor and Prompt: https://github.com/rungalileo/llm-monitor/blob/1a42e5275dc5d4bb6b11219284269f44b02cab3b/llm_monitor/utils/api_client.py#L72-L89

Testing

https://fmpm.dev/mocking-auth0-tokens

Local example

My local token was expired but it used the local env to refresh succesfully.

>>> import os
>>> import jwt
>>> from time import time
>>> from dataquality.core._config import config

>>> os.environ["GALILEO_USERNAME"] = "<redacted>"
>>> os.environ["GALILEO_PASSWORD"] = "<redacted>"
>>> token = config.token
>>> exp = jwt.decode(token, options={"verify_signature": False})
>>> exp
{'sub': '<redacted>', 'id': '<redacted>', 'exp': 1700681062}
>>> time() > exp["exp"]
True

>>> ApiClient().get_current_user()
<response redacted>  # response succesful with refresh token

Comment on lines -18 to -41
def email_login(self) -> None:
username = os.getenv("GALILEO_USERNAME")
password = os.getenv("GALILEO_PASSWORD")
res = requests.post(
f"{config.api_url}/login",
data={
"username": username,
"password": password,
"auth_method": "email",
},
headers={"X-Galileo-Request-Source": "dataquality_python_client"},
)
if res.status_code != 200:
raise GalileoException(
(
f"Issue authenticating: {res.json()['detail']} "
"If you need to reset your password, "
f"go to {config.api_url.replace('api', 'console')}/forgot-password"
)
)

access_token = res.json().get("access_token")
config.token = access_token
config.update_file_config()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

i really don't like that we did this in auth

Copy link
Contributor

Choose a reason for hiding this comment

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

@elboy3 elboy3 changed the title Feat/token refresh feat: token refresh Dec 14, 2023
@codecov-commenter
Copy link

codecov-commenter commented Dec 14, 2023

Codecov Report

Attention: 3 lines in your changes are missing coverage. Please review.

Comparison is base (6c5c9f9) 86.57% compared to head (0c85f9b) 86.59%.

Files Patch % Lines
dataquality/clients/api.py 95.45% 2 Missing ⚠️
dataquality/core/auth.py 80.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #818      +/-   ##
==========================================
+ Coverage   86.57%   86.59%   +0.02%     
==========================================
  Files         196      196              
  Lines       15728    15767      +39     
==========================================
+ Hits        13617    13654      +37     
- Misses       2111     2113       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@elboy3 elboy3 marked this pull request as ready for review December 14, 2023 22:13
@elboy3 elboy3 requested review from dcaustin33 and a team as code owners December 14, 2023 22:13
@elboy3 elboy3 enabled auto-merge (squash) December 15, 2023 15:21
@elboy3 elboy3 merged commit 657e1cb into main Dec 15, 2023
@elboy3 elboy3 deleted the feat/token-refresh branch December 15, 2023 15:27
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