-
Notifications
You must be signed in to change notification settings - Fork 127
Add support for client credentials grant #269
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
base: main
Are you sure you want to change the base?
Add support for client credentials grant #269
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #269 +/- ##
============================================
- Coverage 51.45% 48.09% -3.37%
- Complexity 406 434 +28
============================================
Files 30 31 +1
Lines 1028 1100 +72
============================================
Hits 529 529
- Misses 499 571 +72 ☔ View full report in Codecov by Sentry. |
Don't understand create duplicate PR of #257 |
@kuzmany guessing because there has been no response to feedback since September 2021! |
Ok. But still would be good mention what is different between my version and this version. |
Sure thing.
|
@nick-vanpraet could you take a look at the failing tests for this PR please? Appreciate it was a while back, it'd be great to get it tested and merged! @escopecz and @kuzmany we do still need to decide to merge this in favour of the older PR. It seems sensible to do so given the outlined additional functionality. Let's make a decision and get it merged? |
@RCheesley we use #257 for our customers. It's from 2021 then I am not able to say what community need to merge. I see some Dennis comments, but cannot spend more time on it, only for maintenance to push it to branch. It's up to community. As usual I prefer less work for done. |
Tested PR: #269 in my build server and it is working. Just 2x NOTICES need to be fixed:
File:
public function validateAccessToken()
{
$this->log('validateAccessToken()');
//Check to see if token in session has expired
if ( !empty($this->_access_token) && !empty($this->_expires) && $this->_expires < (time() + 10)) {
$this->log('access token expired');
return false;
}
//Check for existing access token
if ( !empty($this->_access_token) ) {
$this->log('has valid access token');
return true;
}
//If there is no existing access token, it can't be valid
return false;
} This is a low risk merge:
I vote to merge and released PR: #269 immediately, as it is a critical missing feature with low-impact. |
@nick-vanpraet looks like there's some code style fixes to be done here, would you take a look please? We also need to have the test coverage increased as you can see from CodeCov. Let us know if you need some help with that! |
I just checked and, it's been 999 days (April 7, 2022 - December 31, 2024) since original PR creator nick-vanpraet last commented. |
@linuxd3v yes, someone needs to take over and see the change being up with the project standards. |
c445d71
to
d101d40
Compare
I think mails are turned off for this repo or something. Anyway: rebased, implemented strlen/empty changes and fixed phpcs. |
@nick-vanpraet thank you sir! @linuxd3v can you please give it a review and a test before the merge? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested this. It works as expected. This will be a great addition in the next release.
@escopecz are we good to merge this with the successful test above? It'd be great to make the release, perhaps in time with 7.0? |
@@ -0,0 +1,270 @@ | |||
<?php | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
declare(strict_types=1); | |
/** | ||
* OAuth Client modified from https://code.google.com/p/simple-php-oauth/. | ||
*/ | ||
class TwoLeggedOAuth2 extends AbstractAuth |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think we could make this class final and add real property, param and return types to avoid BC breaks when doing this later on?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I personally absolutely despise final
. If a developer using this package wants to make a small tweak to this class for a specific setup, they would have to copy the whole thing. If that is what we want to force, I can add it. But there was an issue I was working on in Mautic that could have been very easily and cleanly solved if a certain Symfony class did not have final
set.
Typehinting fo sho though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree with @nick-vanpraet
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inheritance creates a multi-layered mess. A good example are Mautic controllers and models.
I suggest to google "composition over inheritance" to get good examples why composition is way better practice.
If the architecture is not allowing to change a class then Symfony allows you to decorate the service which is not the point here but it is for Mautic.
Plus, a final class is easier to maintain for a library like this one as developers don't have to think about all the ways how users could have inherited the class and what it could break for them.
I'm not going to block this with these suggestions PR if it gets a second approval as I'm not using this library.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure but IIRC I didn't want to replace anything I just wanted to use the existing logic for something instead of having to re-invent the wheel, just with a minor tweak.
Anyway I don't think it's up to package developers to care if someone else inherits their class. They either do or they don't, we're not their mother. Add an @internal annotation and let them decide if they want to risk it.
Speaking of, I'll add an @internal annotation at least.
Some would require changes to the parent, out of scope for this PR
PR to replace #257 as that one seems abandoned.
Adds support for the client_credentials grant type added in M4 mautic/mautic#9837
I kept as much of the logic that was used in the Oauth Auth class in as I could (the debugging, the weird query parameter access token thing that I'm pretty sure is a security concern, etc).