When dealing with an OAuth-Server which is not supporting the authorization with credentials inside the request body, we can't get the token, only a 401 'Unauthorized' response.
This is because the OAuth 2.0 Client library sets the 'PostAuthOptionProvidor' as default.
When changing this to 'HttpBasicAuthOptionProvider', we get a token from the OAuth-Server.
But i don't think it's a good idea to change default behaviour of the library, so i patched this module by adding the possibility to add the 'optionProvider' in the plugin definition.
For example :
/**
* OAuth2 Client to authenticate with OAuth services
*
* @Oauth2Client(
* id = "my_id",
* name = @Translation("MY ID"),
* grant_type = "client_credentials",
* client_id = "XXXX",
* client_secret = "YYYY",
* authorization_uri = "",
* token_uri = "https://my.token.xy/oauth/token",
* resource_owner_uri = "",
* option_provider = "League\OAuth2\Client\OptionProvider\HttpBasicAuthOptionProvider",
* )
*/
I'm pretty sure there will be a better (writing) solution for this, but these are my first steps into OO.
Any suggestions are appreciated.
| Comment | File | Size | Author |
|---|---|---|---|
| #15 | change_optionprovider-8.x-3.0-beta1-3046879-7.patch | 2.79 KB | pbosmans |
| #6 | change_optionprovider-8.x-2.x-3046879-6.patch | 2.97 KB | imclean |
| #5 | change_optionprovider-8.x-2.x-3046879-5.patch | 1.18 KB | sfuchsbe |
| #4 | change_optionprovider-3046879-4.patch | 1.11 KB | sfuchsbe |
| oauth2_client-optionProvider.patch | 1.19 KB | pbosmans |
Issue fork oauth2_client-3046879
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
Ashley.Sommer commented@pbosmans
Thank you for creating this issue thread. This looks like a good feature addition, and will likely be merged with the next round of feature addition merges. I might change it slightly (by removing "League\OAuth2\Client\OptionProvider\" and having only the final class name).
Comment #3
mrdalesmith commentedThis patch does not cleanly apply because of the /Drupal/web/ paths within it. Can confirm it worked when cleaned up.
Comment #4
sfuchsbe commentedI'm currently facing the same issue and would like to follow up on this thread.
I agree that havint the FQCN configured in the annotation is not perfect, but I was ending up with the same, since class discovery without having the namespace configured seem impossible at the moment - at least for me ;)
I reworked the patch hopefully following the guidelines besed on the mentioned version 8.x-2.0-beta3 - additionally I'm going to provide the same patch for 8.x-2.x branch in a moment.
Comment #5
sfuchsbe commentedThis is a version for 8.x-2.x branch.
In my opinion we should go ahead with reviewing.
Comment #6
imclean commentedThis looks good and probably essential as Basic auth is required by the OAuth2 spec.
I've made a couple of changes:
* PHP League currently states:
It checks for "optionProvider" even though it doesn't mention it in the comment.
It requires a patch from this issue to remove the error on the test page: #3101522: Array to string conversion in Drupal\oauth2_client\Form\ClientTestForm
Comment #7
imclean commentedJust a note that the library's
ClientCredentialsGrantService->getAccessToken()doesn't support scope or any other options.See the issue on github for a possible solution.
Comment #8
imclean commentedWe're using #6 on a production site and it's working well. It would be good to have some feedback on the change of approach.
Comment #9
imclean commentedThis is almost a bug report as the OAuth2 spec requires Basic Auth.
Comment #10
imclean commentedPull request for oauth2-client.
Comment #11
imclean commented#7
See: https://github.com/thephpleague/oauth2-client/issues/774#issuecomment-71...
We'll need to roll our own
HttpBasicAuthOptionProviderto add the scope.Comment #12
imclean commentedI think the patch in #6 is fine. To use scope with HTTP Basic Auth you just need to extend the class.
Can anyone else test #6?
Comment #13
fathershawnHi! @perelesnyk and I have stepped up as maintainers, officially for D9 compatible and forward. I've done a quick review of the patch and it's an interesting approach to passing options to the provider. We will review in more detail after #3072062: Refactor Authorization Token Flow is completed.
Comment #14
fathershawnComment #15
pbosmans commentedPatch updated for version 8.x-3.0-beta1
Comment #16
pbosmans commentedComment #17
fathershawnThis seems like a workable idea, but we should add the collaborators property to the annotation class and set it to a default empty array.
Second, the feature request changes code currently in MR in #3256272: Additional parameters to get Access token so let's get that change in first.
Comment #18
fathershawnWell now we need an option provider in #3157501: Add Scopes to ClientCredentials Grant Type so adding this feature :)
Comment #21
fathershawn