Closed (fixed)
Project:
OAuth 1.0
Version:
8.x-1.x-dev
Component:
User interface
Priority:
Major
Category:
Bug report
Assigned:
Reporter:
Created:
3 Dec 2015 at 10:28 UTC
Updated:
8 Feb 2016 at 10:24 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
juampynr commentedAdjusted title.
Comment #3
willwh commentedComment #4
willwh commentedHere's a patch with a start on this. I'm passing a {user} param in the add route, and then trying to use an AccountInterface in my AddForm to fetch the user, that should be passed in a parameter with this route, although, my $user object is always NULL.
Comment #5
juampynr commentedLooks like you had already the Downloaded version of the module, this change shouldn't be here.
This looks fine to me. I don't know what could be wrong.
Once we find the user, we should check that if we get a user object, the current user should have enough permissions to perform this action. Otherwise, authenticated users could create keys for other users.
Comment #6
willwh commentedHere's another patch. I'd love if you could take a look.
Seems that keys are being created properly per user now, but they are not visible, which is bizarre, as they exist in the database.
I'm going to keep digging on this, but if you have any thoughts, I'm all ears :)
Comment #7
willwh commentedLooks like it was a cache issue, hah :/
The #6 seems to work well, I'm going to work on some custom auth checks now to make sure people can't mess with other users keys.
Comment #8
willwh commentedSo I have some custom auth checking going on.
There is one problem to iron out here... Logged in as an admin user, this works great.
Logging in as a regular user, the oauth.user_consumer route seems to get cached.
I can add and delete keys, although the list itself is never updated. However, you can check in mysql and see the keys being added and deleted successfully.
I'm probably missing something, thought I'd throw this patch up anyway :)
Comment #9
willwh commentedOops, that patch was missing some stuff, here we go!
Comment #10
juampynr commentedLooks like this method is not needed for what I have seen in Drupal core. The AccessInterface is empty.
I don't think that the uid adds useful information to the site admin. Can we keep the message as it is?
Missing comma :neckbeard:
Looking good! We should adjust the module tests so they cover the logic that you are adding in this patch.
Comment #11
willwh commentedComment #12
willwh commentedOk, I went off down the rabbit hole... and this patch is a large refactor of the way we are storing consumers, it's all chx's fault. (Thanks for the guidance @chx)
I am happy to split this out in to a couple of patches, let me know if you'd like to do that...
I'm opting for storing consumers as UserData (and using the 'user.data' service, instead of using a custom SQL table)
Let me know if you want me to split this patch up in to this issue, and then perhaps one for a refactor of consumer storage?
I thought I'd wait on updating tests until I know what you'd like to do here.
Thanks, this has been fun and I've learned a lot! :)
Comment #13
willwh commentedThis patch allows admin users to administer other users keys.
This patch introduces a new custom access check for routes, and a new way of storing consumer data (in UserData).
I've got tests passing locally. Happy Hogmanay!
Comment #14
willwh commentedComment #15
willwh commentedActually, I re-ran tests today, and realized my patch removed the schema from the .install, and I ran tests prior.
Running tests and the last test pukes, so tests still require work, back at it next week some time ;)
Comment #16
willwh commentedOk, tests passing now, I forgot to remove the hook_user_delete() which was calling db_delete on a non-existent table, now that we're using UserData :)
Comment #17
juampynr commentedAwesome work @willwh!
Here is my feedback:
We need a database update that ports existing data to the new architecture. This allows existing sites to upgrade to the new version.
Why is this a loop?
Indentation.
Why this is a loop?
Loop?
Loop?
Comment #18
willwh commentedI have these loops fixed in my local, just trying to understand how I write this update hook to port consumer data and then delete the old schema ;)
Comment #19
juampynr commentedI did something similar for Metatag module. You can get an idea of the process here: http://cgit.drupalcode.org/metatag/tree/metatag.install?h=8.x-1.x#n217.
Here is how I would do it:
1. Re-install Drupal to make sure that there are no remainings of oauth.
2. Install the current version of oauth.
3. Add a few keys to some users.
4. Dump the database into a file (in case we want to run the database update again).
5. Write a database update that:
5.1 Loads all keys.
5.2 Adds the keys to each user via UserData.
5.3 Deletes the custom oauth table.
Comment #20
willwh commentedHere we go :D
Comment #21
juampynr commentedThis is not needed in this kind of hook. It results in confusing reporting when you run database updates via the web interface or drush. Keep the description but please remove the Implements...
As per https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Extension..., this should be 8100.
Missing period :neckbeard:
Can we load the service into a variable first instead of invoking it on every loop?
Is this needed in the class?
Indentation.
Is this needed?
Is this needed?
Comment #22
willwh commentedHow's this? :)
Comment #23
juampynr commentedMissing brackets.
Indentation.
Comment #24
willwh commentedDoh, here we go!
Comment #25
juampynr commentedComment #33
deviantintegral commentedLooks like the patch file got added to the patch?
+++ b/oauth-admin-2627994-22.patch
Comment #34
deviantintegral commentedphpcs is showing errors added in this patch. I'm about to submit a phpcbf run against 8.x-1.x, but even after merging that here I'm getting the following. This is also failing all the tests on my local, so I haven't done an in-depth review yet.
FILE: ...nt/d8/www/docroot/modules/oauth/src/Access/CustomAccessCheck.php ---------------------------------------------------------------------- FOUND 4 ERRORS AFFECTING 3 LINES ---------------------------------------------------------------------- 21 | ERROR | Doc comment short description must be on a single line, | | further text should be a separate paragraph 23 | ERROR | Missing parameter comment 23 | ERROR | Missing parameter name 27 | ERROR | Return comment must be on the next line ---------------------------------------------------------------------- FILE: ...odules/oauth/src/Authentication/Provider/OAuthDrupalProvider.php ---------------------------------------------------------------------- FOUND 2 ERRORS AFFECTING 2 LINES ---------------------------------------------------------------------- 26 | ERROR | Class property $user_data should use lowerCamel naming | | without underscores 45 | ERROR | Missing parameter name ---------------------------------------------------------------------- FILE: .../d8/www/docroot/modules/oauth/src/Controller/OAuthController.php ---------------------------------------------------------------------- FOUND 2 ERRORS AFFECTING 2 LINES ---------------------------------------------------------------------- 34 | ERROR | Class property $user_data should use lowerCamel naming | | without underscores 42 | ERROR | Parameter tags must be grouped together in a doc | | comment ---------------------------------------------------------------------- FILE: ...t/d8/www/docroot/modules/oauth/src/Form/OAuthAddConsumerForm.php ---------------------------------------------------------------------- FOUND 1 ERROR AFFECTING 1 LINE ---------------------------------------------------------------------- 37 | ERROR | Class property $user_data should use lowerCamel naming | | without underscores ---------------------------------------------------------------------- FILE: ...8/www/docroot/modules/oauth/src/Form/OAuthDeleteConsumerForm.php ---------------------------------------------------------------------- FOUND 7 ERRORS AFFECTING 4 LINES ---------------------------------------------------------------------- 39 | ERROR | Class property $user_data should use lowerCamel naming | | without underscores 64 | ERROR | Missing parameter comment 64 | ERROR | Missing parameter name 66 | ERROR | Parameter tags must be grouped together in a doc | | comment 66 | ERROR | Missing parameter comment 66 | ERROR | Missing parameter name 76 | ERROR | Public method name "OAuthDeleteConsumerForm::getFormID" | | is not in lowerCamel format ---------------------------------------------------------------------- FILE: ...rew/vagrant/d8/www/docroot/modules/oauth/src/Tests/OAuthTest.php ---------------------------------------------------------------------- FOUND 3 ERRORS AFFECTING 3 LINES ---------------------------------------------------------------------- 28 | ERROR | Visibility must be declared on method "testConsumers" 74 | ERROR | Visibility must be declared on method | | "testRequestAuthentication" 138 | ERROR | Visibility must be declared on method | | "testConsumerDeletion" ---------------------------------------------------------------------- Time: 315ms; Memory: 7.5MbComment #35
willwh commentedWoops! Let's try that again!
Comment #43
willwh commentedAccording to chx, it's not possible to support this in DCI currently:
chx: willwh: you cnat test that on DCI ATM
chx: willwh: it should not be hard to add a plugin to DCI to allow a PECL isntallation step
chx: willwh: but it'd require a C building environment which is slow and slow is expensive
willwh: my tests are passing locally, and I’m okay with that
chx: willwh: and this is a really rare request
are you guys ok with tests passing locally? :)
Comment #44
mikebell_ commentedI've applied this patch to my local codebase and can confirm it does what it's supposed to.
* Applied patch
* drush updb -y
* drush cr
* Confirmed existing keys moved to user.data
* No oauth_consumer table
* Created a key as another user and confirmed uid in user.data
* Delete a key from uid 1 which was removed
* Delete a key from new user which was removed
* Succesfully tested REST endpoint which required oauth key from new user.
Comment #46
juampynr commentedMade the following changes to the patch:
Committed. Thanks!