Problem/Motivation
Currently in v6 the Consumer form only lets you specify default scopes for the consumer if the client_credentials grant type is enabled. But default scopes are granted for any authorization request, regardless of the grant type, when no specific scope is requested.
I believe this is the relevant part of the OAuth2 spec: https://datatracker.ietf.org/doc/html/rfc6749#section-3.3
If the client omits the scope parameter when requesting
authorization, the authorization server MUST either process the
request using a pre-defined default value or fail the request
indicating an invalid scope. The authorization server SHOULD
document its scope requirements and default value (if defined).
Scope clarified in #13
Limiting the allowed scopes only makes sense for client credentials. For more information, see: https://www.drupal.org/project/simple_oauth/issues/3495325
Client credentials can both limit allowed scopes and provide default scopes. Because of this, we can’t make the existing scope field generic, since a consumer may have multiple grant types enabled with different scope policies. Therefore, we need to introduce a dedicated scopes field on the consumer for the authorization code.
Regarding failing the authorization request when at least one scope is not provided, either by the request or by the default scope set on the consumer, this is a valid approach for the authorize controller.
Steps to reproduce
Try to add default scopes to a consumer without the client credentials grant
Proposed resolution
Allow setting default scopes on consumers regardless of selected grant types
Remaining tasks
Implement
User interface changes
Default scopes are always shown in Consumer form
API changes
None
Data model changes
None
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | default-scopes-after.png | 120.33 KB | paul121 |
Issue fork simple_oauth-3398468
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
paul121 commentedComment #4
paul121 commentedAttaching screenshot of what this looks like. The scopes field is available below the 3rd party/confidential fields, but before Redirect URIs.
Comment #5
paul121 commentedComment #7
bojan_dev commentedI made a few changes to support the default scopes in all grant types. Remaining tasks:
Comment #8
kingdutchI just want to note that this is not a bug but rather a feature request (though I'll leave changing the category to others if you agree).
As already shown in the issue summary:
In the initial implementation we specifically chose to go for the "fail the request indicating an invalid scope" route.
In any change we make to this we should ensure that the module can be configured to disallow the use of default scopes and force clients to request some.
Comment #10
claudiu.cristeaComment #11
claudiu.cristeaIn one of our projects, we have a consumer factory and we need to assign scopes to consumers that have also the Authorization Code grant type. Client should not be aware of scopes when performing the request because scopes should be already contained in the consumer. This issue is allowing that (I think in earlier versions of the module this was possible as I saw in one of the YouTube tutorials).
Regarding the failing test, I'm not sure what is the expectancy.
Given this requirement...
I think we should fail when at least one scope is not provided either by request, or as default scope set in the consumer. Or I'm missing something?
Comment #12
claudiu.cristeaOf course, some tests are failing now. With
client_credentialsgrant type, if the scopes were already configured in the consumer, it was not possible to pass an additional one in request. Butauthorization_codedidn't had this constraint. If we apply the same policy toauthorization_codeI don't think it is a BC break, as, until now, it wasn't possible to store scopes inside consumer for this grant type.This needs to get some feedback from the maintainers.
Comment #13
bojan_dev commentedLimiting the allowed scopes only makes sense for client credentials. For more information, see: https://www.drupal.org/project/simple_oauth/issues/3495325
Client credentials can both limit allowed scopes and provide default scopes. Because of this, we can’t make the existing scope field generic, since a consumer may have multiple grant types enabled with different scope policies. Therefore, we need to introduce a dedicated scopes field on the consumer for the authorization code.
Regarding failing the authorization request when at least one scope is not provided, either by the request or by the default scope set on the consumer, this is a valid approach for the authorize controller.
Comment #14
claudiu.cristeaThis means default scopes will be merged with scopes passed to request in order to get the final request scopes?
Comment #15
bojan_dev commentedI wouldn’t merge it; this way, authorization can be requested with fewer scopes than the default if needed.
Comment #16
claudiu.cristeaUpdating the IS after clarified the scope of this issue in #13.
More discussions took place on Slack, see https://drupal.slack.com/archives/C1BMUQ9U6/p1757918379890819
Comment #18
dimilias commentedI have reviewed the patch and works fine. I do not like the redundant comments like "Log in the user" but I see that all tests are like that so it is fine to stay for consistency even if it is unumbered.
Comment #19
bojan_dev commentedComment #20
saidatomComment #21
bojan_dev commentedComment #22
saidatomComment #23
huzookaThe only thing that bothers me is that the word "creds" had to be taken into CSpell ignore while it is only used in
tests/src/Functional/AuthCodeFunctionalTest.php, in the name of a variable and also in a test entity's ID.At the same time, as far as I understand, all the points raised by @bojan_dev are addressed. I give an RTBC in advance but let him decide about the next steps here.
Comment #24
bojan_dev commentedComment #25
saidatomComment #26
bojan_dev commentedI simplified the
loadByGrantType()implementation since the code felt a bit overcomplicated. We only need to load scopes for one grant type anyway, so this should be the final step. If someone could take a look at my last commit, we can go ahead and merge it.Comment #27
saidatomLooks good move to RTBC.
Comment #29
bojan_dev commentedThank you all for your contributions!
Comment #31
claudiu.cristeaNice to see this completed. Thanks to all involved