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: add authentication configs (TCTC-9914) #1842

Open
wants to merge 15 commits into
base: master
Choose a base branch
from

Conversation

julien-pinchelimouroux
Copy link
Contributor

@julien-pinchelimouroux julien-pinchelimouroux commented Dec 2, 2024

Implements new authentication configuration on HTTP API connectors
Everything is described in the PAT : https://toucantoco.atlassian.net/wiki/spaces/TTA/pages/4645355521/PAT+278+--+HTTP+connector+oAuth2+management

@julien-pinchelimouroux julien-pinchelimouroux self-assigned this Dec 4, 2024
@julien-pinchelimouroux julien-pinchelimouroux added enhancement New feature or request Need Review python Pull requests that update Python code labels Jan 8, 2025
@julien-pinchelimouroux julien-pinchelimouroux marked this pull request as ready for review January 8, 2025 14:40
@julien-pinchelimouroux julien-pinchelimouroux requested a review from a team as a code owner January 8, 2025 14:40
@julien-pinchelimouroux julien-pinchelimouroux changed the title feat: add authentication configs - wip feat: add authentication configs (TCTC-9914) Jan 8, 2025

Call refresh token route if the access token has expired.
"""
oauth_token_info = self._secrets_keeper.load(self.auth_flow_id)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

model pydantic

Copy link

@Fanaen Fanaen left a comment

Choose a reason for hiding this comment

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

Looks good to me, thanks for the hard work 👍

Copy link
Contributor

@lukapeschke lukapeschke left a comment

Choose a reason for hiding this comment

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

Nice work, gg 🏅 A few remarks but nothing blocking. Also, could you please add all files in toucan_connectors/http_api to the list of files checked by mypy in pyproject.toml ?

Comment on lines +46 to +57
if isinstance(token_response["expires_at"], str):
expires_at = None
for date_format in _SUPPORTED_EXPIRATION_FORMATS:
try:
expires_at = datetime.strptime(token_response["expires_at"], date_format)
break
except ValueError:
continue
if expires_at is not None:
return expires_at
raise ValueError(f"Can't parse the oauth2 token expiration: {token_response['expires_at']}")
return datetime.fromtimestamp(int(token_response["expires_at"]))
Copy link
Contributor

Choose a reason for hiding this comment

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

could we maybe use a pydanti validator for that ? It would handle key errors, type errors etc

raise ValueError(f"Can't parse the oauth2 token expiration: {token_response['expires_at']}")
return datetime.fromtimestamp(int(token_response["expires_at"]))
else:
return datetime.now() + timedelta(0, int(token_response.get("expires_in", default_lifetime)))
Copy link
Contributor

Choose a reason for hiding this comment

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

note: dateutil's timedelta is smarter. Also, you you please use kwargs for the timedelta ?


:param workflow_callback_context: the context which will be passed to the workflow token saver callback
"""
pass
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
pass

can be omitted when there's a docstring

authorization_response: str,
):
"""Retrieve authorization token from oauth2 backend"""
pass
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
pass

raise MissingOauthWorkflowError()

# Verify the oauth2 workflow token
assert workflow_token == JsonWrapper.loads(url_params["state"][0])["workflow_token"]
Copy link
Contributor

Choose a reason for hiding this comment

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

same here, could we use pydantic to load the params ? They're user-provided input so it could be anything

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Need Review python Pull requests that update Python code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants