← 返回首页
feat(client): replace basic auth with OAuth ROPC flow by nejch · Pull Request #2422 · python-gitlab/python-gitlab · GitHub
Skip to content

Navigation Menu

Toggle navigation
Sign in
Appearance settings
Search or jump to...

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Include my email address so I can be contacted

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Resetting focus

feat(client): replace basic auth with OAuth ROPC flow#2422

Draft
nejch wants to merge 1 commit into
mainfrom
feat/oauth2-resource-password-flow
Draft

feat(client): replace basic auth with OAuth ROPC flow#2422
nejch wants to merge 1 commit into
mainfrom
feat/oauth2-resource-password-flow

Conversation

Copy link
Copy Markdown
Member

nejch commented Dec 11, 2022

Small step towards #1195, and also to get rid of the old username/password auth.

Also gets rid of the requests-specific HTTPBasicAuth.

Copy link
Copy Markdown

codecov-commenter commented Dec 11, 2022
edited by codecov Bot
Loading

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.17%. Comparing base (45b8930) to head (be7745d).
Report is 148 commits behind head on main.

Current head be7745d differs from pull request most recent head 3733872

Please upload reports for the commit 3733872 to get more accurate results.

Additional details and impacted files
@@ Coverage Diff @@ ## main #2422 +/- ## ========================================== + Coverage 92.16% 96.17% +4.00% ========================================== Files 88 88 Lines 5708 5692 -16 ========================================== + Hits 5261 5474 +213 + Misses 447 218 -229
Flag Coverage Δ
api_func_v4 82.57% <81.81%> (?)
cli_func_v4 82.80% <51.51%> (-0.44%) ⬇️
unit 87.66% <100.00%> (-0.35%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
gitlab/client.py 98.81% <100.00%> (+2.55%) ⬆️
gitlab/oauth.py 100.00% <100.00%> (ø)

... and 50 files with indirect coverage changes

nejch force-pushed the feat/oauth2-resource-password-flow branch 2 times, most recently from 7b1a20d to 90be806 Compare December 19, 2022 15:02
Comment thread gitlab/client.py
)
self.http_backend = http_backend(**kwargs)

self._set_auth_info()
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment

We have to configure the backend first to be able to make requests in _set_auth_info() because that potentially makes a request to retrieve the OAuth token, so moving this down here.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment

Would it make sense to use an auth class for tracking the data?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment

Maybe, I'm not sure I fully get what you had in mind though :) but it might make this PR grow quite a bit, could you explain a bit what you had in mind and if it's more code we can maybe expand in a follow-up?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment

It seems like client is a monolithic class. Moving auth properties and functions to an auth class would be easier to maintain. IMO, implementing the auth class should come first before switching to a different method.

nejch requested a review from lmilbaum December 19, 2022 15:23
Copy link
Copy Markdown
Member Author

nejch commented Dec 19, 2022

@lmilbaum this should also help get rid of requests.HTTPBasicAuth for the backend migration, as I just pass a generic tuple in here when used. Both httpx and requests accept tuples.

Comment thread gitlab/client.py
user_agent: str = gitlab.const.USER_AGENT,
retry_transient_errors: bool = False,
keep_base_url: bool = False,
*,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment

What does this * mean?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment

@lmilbaum It means that all arguments following are required to be keyword-only arguments.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment

@JohnVillalovos Thanks for the clarification. I wasn't aware of this Python feature. BTW, does it make sense to specify the oauth_credentials argument in the kwargs such that it doesn't affect the function signature?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment

@lmilbaum I think that would lose some of the explicitness. That's actually why I added the * here, so it doesn't affect the users as much even if the signature changes a bit. Are you worried about the typing in the backends code?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment

Personally, I don't like function signatures with a large amount of arguments. On the other hand, the explicitness argument is stronger.

Comment thread gitlab/client.py
self.http_username, self.http_password
)

if self.oauth_credentials:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment

What if a user provides both oauth_credentials and http_username and/or http_password?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment

If it's only one of them it will already fail earlier. But if it's both it will ignore them and use oauth. I can make this more explicit as well :)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment

IMO, this use case should be checked and an error should be thrown.

Comment thread gitlab/client.py
)
self.http_backend = http_backend(**kwargs)

self._set_auth_info()
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment

Would it make sense to use an auth class for tracking the data?

Copy link
Copy Markdown
Member Author

nejch left a comment

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment

@lmilbaum I just realized I left my responses as Pending for weeks :( just clicking submit now :)

Comment thread gitlab/client.py
user_agent: str = gitlab.const.USER_AGENT,
retry_transient_errors: bool = False,
keep_base_url: bool = False,
*,
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment

@lmilbaum I think that would lose some of the explicitness. That's actually why I added the * here, so it doesn't affect the users as much even if the signature changes a bit. Are you worried about the typing in the backends code?

Comment thread gitlab/client.py
)
self.http_backend = http_backend(**kwargs)

self._set_auth_info()
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment

Maybe, I'm not sure I fully get what you had in mind though :) but it might make this PR grow quite a bit, could you explain a bit what you had in mind and if it's more code we can maybe expand in a follow-up?

Comment thread gitlab/client.py
self.http_username, self.http_password
)

if self.oauth_credentials:
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment

If it's only one of them it will already fail earlier. But if it's both it will ignore them and use oauth. I can make this more explicit as well :)

nejch force-pushed the feat/oauth2-resource-password-flow branch from 90be806 to be7745d Compare February 16, 2023 19:22
nejch force-pushed the feat/oauth2-resource-password-flow branch from be7745d to 7e65adc Compare October 12, 2023 11:16
nejch marked this pull request as draft October 12, 2023 12:03
nejch force-pushed the feat/oauth2-resource-password-flow branch from 7e65adc to 3733872 Compare June 8, 2024 19:29
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.

4 participants

Footer

© 2026 GitHub, Inc.