Skip to content

Fully support JSON in the IDP - #932

Merged
jvherweg merged 8 commits into
versions/2.0.0from
feat/idp-architecture
Sep 8, 2021
Merged

jvherweg merged 8 commits into
versions/2.0.0from
feat/idp-architecture

Conversation

@jvherweg

@jvherweg jvherweg commented Aug 27, 2021 •

Copy link
Copy Markdown
Member

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.acl as 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?

@jvherweg jvherweg added the semver.major Requires a major version bump label Aug 27, 2021
@jvherweg
jvherweg requested a review from RubenVerborgh August 27, 2021 12:49
@jvherweg
jvherweg force-pushed the feat/idp-architecture branch from 8cf7e01 to 5cb51e9 Compare August 27, 2021 13:11
@RubenVerborgh

Copy link
Copy Markdown
Member

Many errors are going to give a 500 error since we use assert.

Maybe we should have our own assert functions that return more appropriate errors?

@RubenVerborgh

Copy link
Copy Markdown
Member

IDP Integration tests still use the HTML data.

Let's keep it that way.

@RubenVerborgh RubenVerborgh left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great stuff 👍👍👍

Given the new BaseHttpHandler, we might want to move some stuff out of ldp into server (and perhaps name it http).

Comment thread src/server/BaseHttpHandler.ts Resolved
Comment thread src/util/StreamUtil.ts Resolved
@jvherweg

jvherweg commented Sep 7, 2021

Copy link
Copy Markdown
Member Author

Maybe we should have our own assert functions that return more appropriate errors?

Would be a good solution

@jvherweg

jvherweg commented Sep 7, 2021

Copy link
Copy Markdown
Member Author

Given the new BaseHttpHandler, we might want to move some stuff out of ldp into server (and perhaps name it http).

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
@jvherweg
jvherweg force-pushed the feat/idp-architecture branch from 5cb51e9 to ac8f280 Compare September 8, 2021 09:54
@jvherweg
jvherweg merged commit e31cd38 into versions/2.0.0 Sep 8, 2021
@jvherweg
jvherweg deleted the feat/idp-architecture branch September 8, 2021 11:55
@jvherweg jvherweg added this to the v2.0.0 milestone Oct 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

semver.major Requires a major version bump

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants