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

Allow CompositeAuth auth methods to use their own user if defined #20308

Merged
merged 3 commits into from
Jan 14, 2025

Conversation

mtangoo
Copy link
Contributor

@mtangoo mtangoo commented Jan 13, 2025

Q A
Is bugfix? ✔️
New feature?
Breaks BC?
Fixed issues #20238

@mtangoo mtangoo requested a review from a team January 13, 2025 16:50
Copy link

codecov bot commented Jan 13, 2025

Codecov Report

Attention: Patch coverage is 60.00000% with 2 lines in your changes missing coverage. Please review.

Project coverage is 64.84%. Comparing base (fd866da) to head (e9f7a54).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
framework/filters/auth/CompositeAuth.php 60.00% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master   #20308      +/-   ##
============================================
- Coverage     64.84%   64.84%   -0.01%     
- Complexity    11424    11427       +3     
============================================
  Files           431      431              
  Lines         37172    37177       +5     
============================================
+ Hits          24106    24109       +3     
- Misses        13066    13068       +2     

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

@samdark samdark requested a review from bizley January 13, 2025 19:13
@bizley
Copy link
Member

bizley commented Jan 13, 2025

I see this was discussed and proposed to be changed in 2.2. Are we doing this in 2.0 anyway?

@samdark
Copy link
Member

samdark commented Jan 13, 2025

@bizley I don't see any compatibility issues with this change. Are there any?

@mtangoo
Copy link
Contributor Author

mtangoo commented Jan 14, 2025

I see this was discussed and proposed to be changed in 2.2. Are we doing this in 2.0 anyway?

I think in 2.2 there will be a need to look at the API design itself and if necessary make breaking change. This is a "painkiller" approach to just fix the issue without any breaking changes

@bizley
Copy link
Member

bizley commented Jan 14, 2025

With this change user set in the inner auth method will be used for it, now we are using user set in the composite auth.

@mtangoo
Copy link
Contributor Author

mtangoo commented Jan 14, 2025

With this change user set in the inner auth method will be used for it, now we are using user set in the composite auth.

Only if is set. Otherwise it works as it used to!

@bizley
Copy link
Member

bizley commented Jan 14, 2025

With this change user set in the inner auth method will be used for it, now we are using user set in the composite auth.

Only if is set. Otherwise it works as it used to!

Yes, but now even if user is set in one of the methods it is ignored.

@mtangoo
Copy link
Contributor Author

mtangoo commented Jan 14, 2025

With this change user set in the inner auth method will be used for it, now we are using user set in the composite auth.

Only if is set. Otherwise it works as it used to!

Yes, but now even if user is set in one of the methods it is ignored.

Isn't that the purpose of defining user in auth method, that you want it to override anything else defined?

@bizley
Copy link
Member

bizley commented Jan 14, 2025

With this change user set in the inner auth method will be used for it, now we are using user set in the composite auth.

Only if is set. Otherwise it works as it used to!

Yes, but now even if user is set in one of the methods it is ignored.

Isn't that the purpose of defining user in auth method, that you want it to override anything else defined?

I agree but this is BC break as was stated in #20238

@mtangoo
Copy link
Contributor Author

mtangoo commented Jan 14, 2025

I take it as a bug, because otherwise what is the point of an API allowing devs to pass user object of their choice if it ends up being discarded?

IMO, this is a bug that wasn't uncovered for so long.

@samdark
Copy link
Member

samdark commented Jan 14, 2025

I view it as a bug as well. I can't imagine a good scenario where this override is defined but everything works because it's ignored.

@terabytesoftw
Copy link
Member

In my opinion we should fix the bugs that appear in Yii2, what's the point of not doing BC and having bugs is my two cents.

@bizley
Copy link
Member

bizley commented Jan 14, 2025

I agreed with @schmunk42 on this being potentially problematic. I would like to have it change anyway. If you want to proceed with the change I don't mind.

@mtangoo
Copy link
Contributor Author

mtangoo commented Jan 14, 2025

I agreed with @schmunk42 on this being potentially problematic. I would like to have it change anyway. If you want to proceed with the change I don't mind.

I agree with you on this needing a change. But this can be discussed and changed in 2.2, I guess

@samdark samdark merged commit b0b7832 into yiisoft:master Jan 14, 2025
86 of 87 checks passed
@samdark
Copy link
Member

samdark commented Jan 14, 2025

Alright. Let's have it. Thanks, @mtangoo

@samdark samdark added this to the 2.0.52 milestone Jan 14, 2025
@spmaxinc
Copy link

In my original message, I also mentioned $request and $response having the same fate as the $user. If I remember correctly (sorry, can't study the code in detail right now), $request and $response could also be configured for different auth methods, but they were ignored in CompositeAuth. Was this changed/fixed or pushed back? It was not an issue that I ran into. I just ran into the $user issue, but looking back then, both $request and $response were ignored if they were set/defined in authorization methods.

@mtangoo
Copy link
Contributor Author

mtangoo commented Jan 14, 2025

In my original message, I also mentioned $request and $response having the same fate as the $user. If I remember correctly (sorry, can't study the code in detail right now), $request and $response could also be configured for different auth methods, but they were ignored in CompositeAuth. Was this changed/fixed or pushed back? It was not an issue that I ran into. I just ran into the $user issue, but looking back then, both $request and $response were ignored if they were set/defined in authorization methods.

Can you explain how do you pass a different request or response object in Yii2. Can you provide a use case of that scenario?

@spmaxinc
Copy link

spmaxinc commented Jan 14, 2025

For example, let's say I want to use HttpBasicAuth and HttpBearerAuth in CompositeAuth. Each of HttpBasicAuth and HttpBearerAuth allows separate configuration of $response and $request components in themselves, which is expected. However, these $response and $request configured in HttpBasicAuth and HttpBearerAuth will not be respected by CompositeAuth. Their configuration is not passed into CompositeAuth, because CompositeAuth defines its own $request and $response (or null), and by default CompositeAuth will take $response and $request from the app config and not from Auth components passed into it.

@spmaxinc
Copy link

spmaxinc commented Jan 14, 2025

Side comment, which I want to make sure we do not overlook and kill this class all together. I don't think it is emphasized enough in the documentation.

The cool thing about CompositeAuth is not that it may be simplifying several methods of authentication, but most importantly it allows OR logic. If you were to simply list the AuthMethods in controller that will create AND logic, which is probably not what you want.

@mtangoo
Copy link
Contributor Author

mtangoo commented Jan 14, 2025

I will make a followup PR to finalize the overlooked part

@mtangoo
Copy link
Contributor Author

mtangoo commented Jan 14, 2025

Side comment, which I want to make sure we do not overlook and kill this class all together. I don't think it is emphasized enough in the documentation.

The cool thing about CompositeAuth is not that it may be simplifying several methods of authentication, but most importantly it allows OR logic. If you were to simply list the AuthMethods in controller that will create AND logic, which is probably not what you want.

Yii have a lot of parts that are cool and underutilized by devs. Partly is because many ofnits devs don't write or make a lot of videos tuts

@schmunk42
Copy link
Contributor

Yii have a lot of parts that are cool and underutilized by devs. Partly is because many ofnits devs don't write or make a lot of videos tuts

Maybe we can have an AI make video tutorials from written documentation. 😆

@mtangoo
Copy link
Contributor Author

mtangoo commented Jan 15, 2025

Yii have a lot of parts that are cool and underutilized by devs. Partly is because many ofnits devs don't write or make a lot of videos tuts

Maybe we can have an AI make video tutorials from written documentation. 😆

May be. But a touch of humanity always beats the robots 😉

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.

6 participants