Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

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

Provide feedback

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

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
nejch wants to merge1 commit intomain
base:main
Choose a base branch
Loading
fromfeat/oauth2-resource-password-flow

Conversation

nejch
Copy link
Member

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

Also gets rid of the requests-specificHTTPBasicAuth.

@codecov-commenter
Copy link

codecov-commenter commentedDec 11, 2022
edited by codecovbot
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 headbe7745d differs from pull request most recent head3733872

Pleaseupload reports for the commit3733872 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
FlagCoverage Δ
api_func_v482.57% <81.81%> (?)
cli_func_v482.80% <51.51%> (-0.44%)⬇️
unit87.66% <100.00%> (-0.35%)⬇️

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

FilesCoverage Δ
gitlab/client.py98.81% <100.00%> (+2.55%)⬆️
gitlab/oauth.py100.00% <100.00%> (ø)

... and50 files with indirect coverage changes

@nejchnejchforce-pushed thefeat/oauth2-resource-password-flow branch 2 times, most recently from7b1a20d to90be806CompareDecember 19, 2022 15:02

#: Create a session object for requests
http_backend: Type[http_backends.DefaultBackend] = kwargs.pop(
"http_backend", http_backends.DefaultBackend
)
self.http_backend = http_backend(**kwargs)

self._set_auth_info()
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

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.

Choose a reason for hiding this comment

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

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

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

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?

Choose a reason for hiding this comment

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

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.

@nejchnejch requested a review fromlmilbaumDecember 19, 2022 15:23
@nejch
Copy link
MemberAuthor

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

@@ -75,6 +76,8 @@ def __init__(
user_agent: str = gitlab.const.USER_AGENT,
retry_transient_errors: bool = False,
keep_base_url: bool = False,
*,

Choose a reason for hiding this comment

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

What does this* mean?

Choose a reason for hiding this comment

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

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

Choose a reason for hiding this comment

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

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

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

@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?

Choose a reason for hiding this comment

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

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

self.http_username, self.http_password
)

if self.oauth_credentials:

Choose a reason for hiding this comment

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

What if a user provides bothoauth_credentials andhttp_username and/orhttp_password?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

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 :)

Choose a reason for hiding this comment

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

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


#: Create a session object for requests
http_backend: Type[http_backends.DefaultBackend] = kwargs.pop(
"http_backend", http_backends.DefaultBackend
)
self.http_backend = http_backend(**kwargs)

self._set_auth_info()

Choose a reason for hiding this comment

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

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

Copy link
MemberAuthor

@nejchnejch left a comment

Choose a reason for hiding this comment

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

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

lmilbaum reacted with laugh emoji
@@ -75,6 +76,8 @@ def __init__(
user_agent: str = gitlab.const.USER_AGENT,
retry_transient_errors: bool = False,
keep_base_url: bool = False,
*,
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

@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?


#: Create a session object for requests
http_backend: Type[http_backends.DefaultBackend] = kwargs.pop(
"http_backend", http_backends.DefaultBackend
)
self.http_backend = http_backend(**kwargs)

self._set_auth_info()
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

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?

self.http_username, self.http_password
)

if self.oauth_credentials:
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

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 :)

@nejchnejchforce-pushed thefeat/oauth2-resource-password-flow branch from90be806 tobe7745dCompareFebruary 16, 2023 19:22
@nejchnejchforce-pushed thefeat/oauth2-resource-password-flow branch frombe7745d to7e65adcCompareOctober 12, 2023 11:16
@nejchnejch marked this pull request as draftOctober 12, 2023 12:03
@nejchnejchforce-pushed thefeat/oauth2-resource-password-flow branch from7e65adc to3733872CompareJune 8, 2024 19:29
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@JohnVillalovosJohnVillalovosJohnVillalovos left review comments

@lmilbaumlmilbaumlmilbaum requested changes

Assignees

@nejchnejch

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

4 participants
@nejch@codecov-commenter@JohnVillalovos@lmilbaum

[8]ページ先頭

©2009-2025 Movatter.jp