Skip to content

IDP error reporting from oidc-provider #1061

Closed

Description

@josephguillaume

There's an increasing number of questions on the solid project forum about problems with client authentication or rejected authentication requests. These are (deliberately) hard to debug on the client side, but CSS provides an ideal platform to help debug on the server side, i.e. we could encourage users to install CSS and look at the debug messages.

As mentioned in another issue (#909 (comment)) reporting of IDP errors is currently minimal.

I've personally taken to including console.log statements in the relevant files for node_modules for oidc-provider. That's obviously not the right approach.
Any thoughts on how a proper error reporting set up should be structured?

Activity

  1. RubenVerborgh commented on Nov 11, 2021

    @RubenVerborgh
    Member
  2. added
    ❓question
    on Nov 11, 2021
  3. jvherweg commented on Nov 12, 2021

    @jvherweg
    Member

    Adding logging in our IDP classes can help, but if I understand @josephguillaume correctly, it is actually logging from the OIDC library itself that is required. I have also already added console.log statements to the source of that library at some point to debug some issues. So that's not perfect.

    It depends a bit on what kind of logging you need specifically. It might be interesting to define which logging would be expected and helpful to debug issues. One thing that might already be useful is that it is possible to log the response object that is being sent out by OIDC library: https://github.com/panva/node-oidc-provider/blob/v6.x/docs/README.md#pre--and-post-middlewares , although it is a bit awkward that the logging has to happen after the next call, I have already used this many times to see which access tokens are being sent out.

  4. josephguillaume commented on Nov 12, 2021

    @josephguillaume
    Author

    Thanks!
    I was particularly thinking of logging the messages for client authentication errors that oidc-provider throws and that currently seem to be swallowed somewhere.
    I'll have to do some more digging to see where they are meant to show up.

  5. RubenVerborgh commented on Nov 12, 2021

    @RubenVerborgh
    Member

    seem to be swallowed somewhere

    I'd be surprised is that was the case; have you started CSS with -l debug to increase the log level?

  6. josephguillaume commented on Nov 12, 2021

    @josephguillaume
    Author

    It sounds like questions about reporting of these errors are probably worth addressing case-by-case. Let me know if you'd like me to submit separate issues, or whether discussing them here is the better option.

    Yes, I was using -l debug, but I should also have double-checked the situation rather than answering from memory, sorry. The error is indeed not swallowed. The problem is rather that the description provided was too terse.

    If I put an error in the client id document, it is handled by :
    https://github.com/solid/community-server/blob/c13456c2259538e502a59ce73a226bab2c99c395/src/identity/configuration/IdentityProviderFactory.ts#L254

    This actually results in a conversion warning

    2021-11-12T21:04:49.189Z [WebIdAdapter] debug: Looking for payload data at https://CLIENT.PATH/webid.jsonld#this
    2021-11-12T21:04:49.196Z [IfNeededConverter] debug: Conversion needed for b0 from internal/error to satisfy text/plain;q=1
    2021-11-12T21:04:49.197Z [IfNeededConverter] debug: Conversion needed for b0 from internal/error to satisfy text/plain;q=1
    2021-11-12T21:04:49.200Z [ChainedConverter] warn: No conversion path could be made from internal/error to text/plain,internal/*.
    2021-11-12T21:04:49.201Z [SafeErrorHandler] debug: Recovering from error handler failure: No conversion path could be made from internal/error to text/plain,internal/*.
    2021-11-12T21:04:49.202Z [LinkRelMetadataWriter] debug: Available link relations: 3
    2021-11-12T21:04:49.203Z [ParsingHttpHandler] verbose: Parsed GET operation on https://IDP.PATH/idp/auth
    

    But the server obviously still returns the error: InvalidClientMetadata: invalid_client_metadata

    The issue here is that this is a very common error and we actually want to report the error_description.
    Here's the full error trace:

    InvalidClientMetadata: invalid_client_metadata
        at Schema.invalidate (/home/josephguillaume/solid-server/community-server-recipes/mashlib/node_modules/oidc-provider/lib/helpers/client_schema.js:373:13)
        at /home/josephguillaume/solid-server/community-server-recipes/mashlib/node_modules/oidc-provider/lib/helpers/client_schema.js:644:18
        at Set.forEach (<anonymous>)
        at Schema.scopes (/home/josephguillaume/solid-server/community-server-recipes/mashlib/node_modules/oidc-provider/lib/helpers/client_schema.js:642:16)
        at new Schema (/home/josephguillaume/solid-server/community-server-recipes/mashlib/node_modules/oidc-provider/lib/helpers/client_schema.js:266:12)
        at new Client (/home/josephguillaume/solid-server/community-server-recipes/mashlib/node_modules/oidc-provider/lib/models/client.js:423:22)
        at add (/home/josephguillaume/solid-server/community-server-recipes/mashlib/node_modules/oidc-provider/lib/models/client.js:400:20)
        at Function.find (/home/josephguillaume/solid-server/community-server-recipes/mashlib/node_modules/oidc-provider/lib/models/client.js:599:24)
        at processTicksAndRejections (node:internal/process/task_queues:96:5)
        at async checkClient (/home/josephguillaume/solid-server/community-server-recipes/mashlib/node_modules/oidc-provider/lib/actions/authorization/check_client.js:78:18)
        at async parseBodyIfPost (/home/josephguillaume/solid-server/community-server-recipes/mashlib/node_modules/oidc-provider/lib/shared/conditional_body.js:7:5)
        at async sessionHandler (/home/josephguillaume/solid-server/community-server-recipes/mashlib/node_modules/oidc-provider/lib/shared/session.js:29:5)
        at async noCache (/home/josephguillaume/solid-server/community-server-recipes/mashlib/node_modules/oidc-provider/lib/shared/no_cache.js:4:3)
        at async authorizationErrorHandler (/home/josephguillaume/solid-server/community-server-recipes/mashlib/node_modules/oidc-provider/lib/shared/authorization_error_handler.js:55:7)
        at async ensureSessionSave (/home/josephguillaume/solid-server/community-server-recipes/mashlib/node_modules/oidc-provider/lib/helpers/initialize_app.js:51:7)
        at async contextEnsureOidc (/home/josephguillaume/solid-server/community-server-recipes/mashlib/node_modules/oidc-provider/lib/shared/context_ensure_oidc.js:4:5) {
      error: 'invalid_client_metadata',
      status: 400,
      statusCode: 400,
      expose: true,
      error_description: 'scope must only contain supported scopes'
    }

    So I think the questions in this specific case are:

    1. Should the requested conversion to "text/plain" be changed to something else, e.g. "application/json", which then uses the ErrorToJsonConverter?
    2. Would it be ok for the error_description to be returned to the client, or should this detail only be reported in the server logs? The use of the errorHandler suggests it would be ok, and the error does have expose: true set.
    3. Is the correct solution here to modify the structure of the error from oidc-provider so that it matches what e.g. ErrorToJsonConverter expects?

    This fix:

        configureErrors(config) {
            config.renderError = async (ctx, out, error) => {
                if(error.error_description) error.details = error.error_description;
                // This allows us to stream directly to to the response object, see https://github.com/koajs/koa/issues/944
                ctx.respond = false;
                const result = await this.errorHandler.handleSafe({ error, preferences: { type: { 'application/json': 1 } } });
                await this.responseWriter.handleSafe({ response: ctx.res, result });
            };
        }

    Would result in this report:

    {"name":"InvalidClientMetadata","message":"invalid_client_metadata","statusCode":400,"details":"scope must only contain supported scopes"}

    Edit: it looks a proper solution would also need to expose error_detail in some cases: https://github.com/panva/node-oidc-provider/blob/main/lib/helpers/errors.js

  7. jvherweg commented on Nov 15, 2021

    @jvherweg
    Member
    1. Should the requested conversion to "text/plain" be changed to something else, e.g. "application/json", which then uses the ErrorToJsonConverter?

    We should parse the accept header and use that. Open issues for that are #1033 and #810.

    1. Would it be ok for the error_description to be returned to the client, or should this detail only be reported in the server logs? The use of the errorHandler suggests it would be ok, and the error does have expose: true set.

    Depends a bit on how much information is provided by that. We could make it an option as we currently do for stack trace: the server wil output the stack trace of errors if you start it with the -t flag.

    1. Is the correct solution here to modify the structure of the error from oidc-provider so that it matches what e.g. ErrorToJsonConverter expects?

    We could also create a new ErrorHandler specifically for IDP errors, but I think just modifying the error object is fine in this specific case.

  8. dynamoRando commented on Jan 18, 2022

    @dynamoRando

    Hi all - I was pointed to this open issue and I would like also to see if possible more verbose output from the Community Solid Server (CSS) in the case of errors.

    I also have been trying to run CSS in verbose logging mode as a teaching tool for myself to get used to Solid. When troubleshooting an "invalid_grant" response (which I understand to be specific to OpenID, not CSS) it would be helpful if I had specific details about what was wrong, even when debugging the outgoing HTTP POST. I'm following the primer here and I am on step 12 to 14.

    I understand per here that an invalid_grant can mean:

    The provided authorization grant (e.g., authorization
    code, resource owner credentials) or refresh token is
    invalid, expired, revoked, does not match the redirection
    URI used in the authorization request, or was issued to
    another client.

    After a lot of time troubleshooting, I finally was able to resolve my issue to myself incorrectly caching the code_verifier value and sending the wrong value. However, I was hopeful that perhaps if CSS had a verbose or developer mode, that it could've told me specifically what I was sending over incorrectly. Specifically, it would be helpful as a learning tool if it told me if the Json Web Token I created (JWT) was malformed, etc.

    Just a suggestion. Thanks!

  9. jvherweg commented on Feb 21, 2022

    @jvherweg
    Member

    I have updated the returned errors in #1166 so they include the information in the error_description. Feel free to reopen if more logging is required.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    ❓question

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions