Problem/Motivation
The UUID is currently used as client ID for the OAuth flow, this becomes problematic for 3rd party clients on self hosted servers as explained here: #3167287: Always load clients through the ClientRepository service
Proposed resolution
Introduce a new base field with a "UniqueField" constraint, which allows the client ID to be specified in the create/update consumer form. This way for example clients can register with their URL and perform DNS name validations.
For existing consumer entities an hook_update needs to be added, where the 'UUID' value is being migrated to the new 'client_id' field.
Issue fork consumers-3310801
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 #3
bojan_dev commentedComment #4
m.stentaExciting to see this! farmOS currently adds a
client_idbase field to Consumer entities itself, so I opened an issue in our queue to coordinate switching over to using this when it gets merged: #3311264: Coordinate upgrade of Consumers module to get client_id base fieldWe will start by pinning our Consumers module to 1.13 and releasing a new version of farmOS, so we can accommodate this change when this gets merged and 1.14 is released.
Thanks again for pushing this forward!!
Comment #5
m.stentaI think you're good to go on this @e0ipso! (Pending any further changes from @bojan_dev regarding
is_asciiand/or other constraints...)We have a strategy to migrate to this new
client_idcoming together on the farmOS side, and we are going to pin to Consumers 1.13 in the meantime: https://www.drupal.org/project/farm/issues/3311264#comment-14709906Comment #6
bojan_dev commentedComment #7
e0ipsoMerging!
Comment #8
e0ipsoBack to RTBC. It turns out the merge button is not working for some reason.
Comment #9
e0ipsoSetting back to NW. I suspect this needs a re-roll.
Comment #10
bojan_dev commented@e0ipso I tried to rebase but there are no changes.
Comment #11
m.stentaMaybe it's just the Drupal/GitLab UI merge button that's not working? But a regular Git merge would work?
Comment #13
e0ipsoAlright, merging in GitLab's UI did the trick.
Thanks all!
Comment #14
m.stentaOops sounds like this broke simple_oauth :-/
#3316519: Token request broken consumer load by client id changed
We seem to be unaffected in farmOS because we were already patching
simple_oauthvia #3167287: Always load clients through the ClientRepository service AND overriding the service ourselves to use our ownclient_idfield.(@bojan_dev is already aware of this, just commenting to add the cross-reference and context.)
Comment #15
kenowax commentedI confirm this broke simple_oauth but seems to be fixed in simple_oauth v6.0.0-beta1.
Only problem is there are some incompatibilities when attempting to update from simple_oauth 5.2.0.
When applying
and
, simple_oauth update 8604 tries to find table consumers__role but was already renamed to old_xxxxxconsumers__roles previously (I do not know from where).
Fixed by renaming the table back to consumer__roles directly via SQL.
Then, the same simple_oauth update tries to remove the field definition which did not exist so a Null exception is thrown.
Added a null-check on line 293.
After that, drush updb works fine and there doesn't seem to be any more problems.
Comment #16
m.stenta@KenowaX - That sounds like an issue with
simple_oauthv6, not Consumers. Can you open an issue over there with these details? Thanks!See also this related issue for the 5.2.x branch of
simple_oauth, which has been fixed. Just waiting for a 5.2.1 release ofsimple_oauth- but hopefully that will solve your issue too, before you need to upgrade tosimple_oauthv6.#3167287: Always load clients through the ClientRepository service
Still worth opening an issue for the v6 upgrade if there are upgrade path issues there (which may be separate from the other issue).
Comment #17
kenowax commentedDone.
Adding link here in case anyone needs it as it is heavily related to consumers update.
https://www.drupal.org/project/simple_oauth/issues/3318917#comment-14771810
Comment #18
berdirThis caused problems for us as well, for a different reason. We have a _lot_ of oauth tokens and trying to resave the consumer entity attempted to invalidate all of them.
There is a way to set an initial value for a field definition, but I think that won't work for the uuid as it's in a different table. Also, this should either do direct SQL queries then or be a post update function. You should never save content entities in a regular update function as you have no idea about the state of your system, could be in the middle of a major update where other modules have not been updated yet.
Comment #19
m.stentaOof thanks for the heads up @Berdir. Glad we waited to update farmOS. We may try to work around this in our pending MR: #3311264: Coordinate upgrade of Consumers module to get client_id base field
I wonder if there is any way to "fix" this for other Consumers users though. I supposed the update hook could be fixed, which would prevent it from happening on sites that haven't updated yet. Too late for sites that have, I imagine.
Fixing the update hook and tagging a new release would avoid the need for us to add another workaround in farmOS though... so that's appealing for us as well. Worth doing?
Comment #21
bojan_dev commentedValid point Berdir!
I made a new MR available which replaces the hook_update with a SQL query, please review: https://git.drupalcode.org/project/consumers/-/merge_requests/6
Not sure what we should do for Drupal instances that already updated, my assumption is that we can't do anything about it.
Comment #22
berdirThe MR seems quite sensible.
Yes, nothing you can do about sites that already updated, if it worked for them then fine, if not then they can use a patch/wait for a new release.
Comment #23
m.stentaThanks for the quick fix @bojan_dev! I haven't tested but it LGTM! Simple. :-)
Comment #24
m.stenta@paul121 and I just tested this and the tokens were not deleted during update.php. RTBC!
Comment #27
eojthebraveThis looks good to me. My interpretation of the issue here is that we don't want to run a save operation on a consumer in the update hook. But we do need to populate the new client_id field with the value from the current UUID field. The new code does that via direct SQL queries rather than via the Entity API. I'm going to merge this in, and then I'll also tag a new release with this updated code.
Thanks for helping get this working.