Repository navigation
Fully support JSON in the IDP - #932
Merged
Merged
Conversation
jvherweg
force-pushed
the
feat/idp-architecture
branch
from
August 27, 2021 13:11
8cf7e01 to
5cb51e9
Compare
Member
Maybe we should have our own assert functions that return more appropriate errors? |
Member
Let's keep it that way. |
RubenVerborgh
approved these changes
Sep 7, 2021
RubenVerborgh
left a comment
Member
There was a problem hiding this comment.
Great stuff 👍👍👍
Given the new BaseHttpHandler, we might want to move some stuff out of ldp into server (and perhaps name it http).
Member
Author
Would be a good solution |
Member
Author
The plan (or more like vague idea) is to go over the entire folder structure when we get close to releasing 2.0.0 (#920) |
This was referenced Sep 8, 2021
Closed
Controls are now used in templates to prevent IDP URL hardcoding
The IDP behaviour has been changed to move all error related knowledge to the IdentityProviderHttpHandler instead of managing it in the Interactionhandlers.
jvherweg
force-pushed
the
feat/idp-architecture
branch
from
September 8, 2021 09:54
5cb51e9 to
ac8f280
Compare
This was referenced Sep 8, 2021
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #690. Closes #722 (can make new issue for new specifics when needed). Updates #693 and #764.
This is a big PR, sorry about that. I could split it up over several PRs if preferred but it seemed to make sense to keep it like this since it's all mostly targetting the same class. The commits are all work independently so those would mostly be the separate PRs.
I'll go over what new first and then go into the remaining issues. But the plan is to move on to other issues and only come back to this once changes are needed for a reason (e.g. having
/idp/registration.aclas was mentioned in another issue).What's new
IDP route behaviour was moved to separate class to clean the main IDP HTTP handler up a bit.
The IDP now accepts JSON objects as input in POST requests. Expected bodies are the same format as the current form data (except you can have an actual boolean instead of the string 'on').
IDP JSON response objects have controls pointing to relevant IDP URLs.
IDP JSON responses no longer have empty prefilled/errorMessage fields if not relevant. I originally had a nicer solution for this but apparently you can't use the
?operator in ejs templates in node 12.x.The similar behaviour between the IDP handler and the LDP handler has been generalized.
The IDP handlers no longer create the prefilled object themselves. The root IDP HTTP handler now handles this. IDP handlers just throw an error if something goes wrong and no longer have an idea that an html template needs to be filled in with data.
Errors can now be JSON depending on content negotiation (also for normal LDP requests).
An example of the error that now gets thrown when an access token needs to be added for registration:
{ "name": "BadRequestHttpError", "message": "Verification token not found. Please add the RDF triple <http://localhost:3000/joachimvh/profile/card#me> <http://www.w3.org/ns/solid/terms#oidcIssuerRegistrationToken> \"97bb8228-5038-4f66-a3c8-ec2f3f03a255\". to the WebID document at http://localhost:3000/joachimvh/profile/card to prove it belongs to you. You can remove this triple again after validation.", "statusCode": 400, "errorCode": "H400", "details": { "quad": "<http://localhost:3000/joachimvh/profile/card#me> <http://www.w3.org/ns/solid/terms#oidcIssuerRegistrationToken> \"97bb8228-5038-4f66-a3c8-ec2f3f03a255\".", "subject": "<http://localhost:3000/joachimvh/profile/card#me>", "predicate": "<http://www.w3.org/ns/solid/terms#oidcIssuerRegistrationToken>", "object": "\"97bb8228-5038-4f66-a3c8-ec2f3f03a255\"" }, "prefilled": { "email": "[email protected]", "webId": "http://localhost:3000/joachimvh/profile/card#me", "register": true }, "apiVersion": "0.2", "authenticating": false, "controls": { "register": "http://localhost:3000/idp/register", "forgotPassword": "http://localhost:3000/idp/forgotpassword", "login": "http://localhost:3000/idp/login" } }Remaning/potential problems
I'm not completely happy with how everything looks right now, but at least it's still contained within a single class. Too much behaviour is still hardcoded. The two main bottlenecks that make everything a bit more complicated is that the OIDC library requires the original request/response objects, but even more the fact that the IDP component has to be aware of the fact that it potentially has to fill in HTML templates. IMO we could resolve several issues if the IDP HTML templates used javascript for the POST requests to get a JSON response from the server and handled the results themselves (showing errors, keeping prefilled data, redirecting to next page on success). The server would then only have to return HTML on GET requests and everything about templates could (mostly) be removed.
Many errors are going to give a 500 error since we use
assert. This will be have to be updated everywhere to have correct status codes (remains for #693).It is now hardcoded that handlers take JSON as input. We will probably at some point need to generalize this so handlers can indicate what they need and/or have a conversion handler somewhere inbetween.
IDP Integration tests still use the HTML data. I could easily change them to use JSON instead now (and they would look much cleaner), but it seemed like not a bad idea to still test the HTML since a lot of users will see this part. Perhaps I should duplicate the tests to have them for both HTML and JSON?