Define endpoint that allows API users to register tokens. By using an entity for tokens, the basic integration is done. The following items need to be handled:
Implement custom access controller for entityImprove error handling: Currently, errors only return{"error":""}Allow anonymous users to register tokensDon't create entries for tokens that already exist for a given network- Refactor canonical URL for push notifications: REST endpoint is currently
/admin/config/services/push_notifications/token/{push_notifications_token}
| Comment | File | Size | Author |
|---|---|---|---|
| #17 | permissions_restful_web_services.png | 122.27 KB | haagendazs |
| #17 | permissions_push_notifications.png | 110.2 KB | haagendazs |
| #15 | d8_port_service-2776901-15.patch | 23.2 KB | mihai7221 |
Comments
Comment #2
mihai7221 commentedBecause we created an entity for the push notifications token, Drupal automatically builds endpoints (GET, POST, DELETE, PATCH) so there's no need for this issue, I will update #2776915: D8 Port: Write API Documentation on how to GET and POST a push_notifications_token entity.
Comment #3
haagendazs commentedComment #4
haagendazs commentedComment #6
haagendazs commentedComment #8
haagendazs commented@canutza: When I tested the web services integration locally, I was able to register a token for an anonymous user (user = 0), so I'll mark this item as done in the list without a code change.
Comment #10
mihai7221 commentedRegarding the refactoring of the canonical URLs, I don't know why, but using
/entity/push_notifications_token, works and not /admin/config/services/push_notifications/token/, this needs to be investigated further.As for the errors messages, we have the HTTP status codes, why we need messages? They may look better, but the status codes are as helpful as the message itself.
Comment #11
haagendazs commentedAgreed on the error messages. They might not be pretty, but the HTTP status codes should be enough. Let's stick with Drupal provides out of the box.
Regarding canonical URLs: I'd like to move the canonical URL of the push notifications token from
/admin/config/services/push_notifications/tokento/push_notifications/token. I'll give it a try and will see if I can also figure out the issue why the canonical URL does not work to create a new token.Comment #13
haagendazs commentedI've changed the canonical URL for token entities to be
/push_notifications/token/{push_notifications_token}. I've marked both pages as admin pages in the routing configuration.I've looked into the issue about creating a new entity over REST vs. deleting it or getting it, and using different URLs. This URL gives a pretty good overview for how this is being done in JavaScript for nodes, users, and terms: https://www.drupal.org/documentation/modules/rest/javascript. It seems that for nodes, the same issue exists. In order to create a new node, the endpoint is
http://example.com/entity/node, whereas to GET the node, the endpoint ishttp://example.com/node/123?_format=json.This article https://www.drupal.org/documentation/modules/rest/post seems to indicate that starting in Drupal 8.2.0, new nodes can be created without the
entitycomponent in the path. I wonder if that will be the same for any entity, but I haven't tried Drupal 8.2.0 yet.Examples for REST integration
Here are the examples that I used to POST tokens, GET tokens, and DELETE tokens. My example site lives at local.sd8.com and I'm using Basic Authorization, which is converted into a hash. The tool I used to play around was Postman. All the examples are HTTP request examples.
POST
=> Status Code
201GET
=> Status Code
200DELETE
=> Status Code
204I think this is ready for review.
Comment #15
mihai7221 commentedI tried to add a token as an anonymous user, however, the permissions didn't quite work. I added a patch to fix this. Please review.
Please make sure to give the users permissions to register tokens and for POST requests for push notifications tokens.
Comment #16
mihai7221 commentedHm, I just realized (as always) that I
mergedwrong from the 8.x-1.x branch, the permissions file is wrong on my branch.Ignore my previous post, I will create a new branch from 8.x-1.x to make sure everything is alright.
Comment #17
haagendazs commented@canutza: Thanks for retrying. I just tried registering a token for an anonymous user again and was able to do so with the latest 8.x-1.x dev branch. The only thing I needed was a valid CSFR token. I've attached my permissions and here's the code I used to register the token:
Comment #18
mihai7221 commentedYup, everything looks good, we can close this issue I suppose.