Registered claims error after upgrading from 5.0.5 to 5.2.0.

Created on 6 January 2022, over 3 years ago
Updated 12 September 2024, 8 months ago

Problem/Motivation

Error: Lcobucci\JWT\Token\RegisteredClaimGiven: Builder#withClaim() is meant to be used for non-registered claims, check the documentation on how to set claim "sub" in Lcobucci\JWT\Token\RegisteredClaimGiven::forClaim() (line 18 of /app/vendor/lcobucci/jwt/src/Token/RegisteredClaimGiven.php).

Steps to reproduce

Setup a Drupal provider.
Setup an external consumer which expects a "sub" field mapping.

Proposed resolution

I don't know if this is a problem with my implementation, simple_oauth or the underlying package. 'sub' is one of the claims fields used by simple_oath default normalizer, but it seems like others would be experiencing this issue.
* Should I override the normalizer and set the claims (getClaimsFromAccount) without 'sub'?
* Is 5.2 compatible with lesser versions (3.4) of lcobucci/jwt? Are others explicitly using lower version?

I downgraded to 5.0.6 and our implementation started working again, but would like to figure out the source of this issue.

FULL TRACE

Lcobucci\JWT\Token\RegisteredClaimGiven: Builder#withClaim() is meant to be used for non-registered claims, check the documentation on how to set claim "sub" in Lcobucci\JWT\Token\RegisteredClaimGiven::forClaim() (line 18 of /app/vendor/lcobucci/jwt/src/Token/RegisteredClaimGiven.php).
Lcobucci\JWT\Token\Builder->withClaim('sub', '5') (Line: 89)
OpenIDConnectServer\IdTokenResponse->getExtraParams(Object) (Line: 51)
League\OAuth2\Server\ResponseTypes\BearerTokenResponse->generateHttpResponse(Object) (Line: 208)
League\OAuth2\Server\AuthorizationServer->respondToAccessTokenRequest(Object, Object) (Line: 87)
Drupal\simple_oauth\Controller\Oauth2Token->handleToken(Object, Object) (Line: 63)
Drupal\simple_oauth\Controller\Oauth2Token->token(Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 564)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 158)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 80)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 67)
Drupal\simple_oauth\HttpMiddleware\BasicAuthSwap->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 50)
Drupal\ban\BanMiddleware->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 708)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Thanks.

πŸ› Bug report
Status

Needs work

Version

5.2

Component

OpenID Connect

Created by

πŸ‡ΊπŸ‡ΈUnited States bfuzze9898

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡¨πŸ‡³China zterry95

    MR !64 works for me.

  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

    For some reason, MR!66 contains a change which is already in 6.0.x, it's that // phpcs:ignore line. The attached patch had that removed and it should apply cleanly.

  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

    Still a slight issue, but now should be ok.

  • First commit to issue fork.
  • Pipeline finished with Success
    over 1 year ago
    Total: 340s
    #38199
  • πŸ‡§πŸ‡¬Bulgaria pfrenssen Sofia

    Cherry-picked commit 0e62f583 into the 6.0.x MR.

  • Pipeline finished with Success
    over 1 year ago
    Total: 194s
    #38201
  • πŸ‡ΊπŸ‡ΈUnited States grasmash

    The patches in this PR seem to do more than resolve BC issues, they introduce new support for ID tokens and ISS claims. Valuable stuff, but a separate issue?

    >The OpenID Connect token id response needed some treatment as-well.

    I'd love to see those parts merged.

  • πŸ‡ΊπŸ‡ΈUnited States grasmash

    @jurgenhaas, @sanduhrs any chance you can tell me how to actually get the id token? /oauth/token only returns the access token.

  • πŸ‡§πŸ‡ͺBelgium gorkagr

    Hi!

    if using this module (v5.2.5) for login in a gitlab instance from a D10, I get the following error with the respective MR:

    Could not authenticate you from OpenIDConnect because "Request uri must have schema. possibly add 'http://' to the request uri?".

    Without the patch, i have the error in #1.

    in gitlab I have 2 login providers: oauth2_generic (works fine) and openid_connect (error)

    Config details:

    gitlab_rails['omniauth_providers'] = [
      {
        name: "openid_connect",
        label: "OIC",
        args: {
          name: 'openid_connect',
          scope: ['openid', 'oauth2_access_to_profile_information'],
          response_type: 'code',
          issuer: 'https://oauth.ddev.site',
          discovery: false,
          uid_field: 'preferred_username',
          client_auth_method: 'basic',
          client_options: {
            identifier: 'gitlab',
            secret: 'gitlab',
            redirect_uri: 'https://gitlab.ddev.site/users/auth/openid_connect/callback',
            userinfo_endpoint: "https://oauth.ddev.site/oauth/userinfo",
            authorization_endpoint: "https://oauth.ddev.site/oauth/authorize",
            token_endpoint: "https://oauth.ddev.site/oauth/token"
          }
        }
      },
     {
       name: "oauth2_generic",
       label: "OAUTH",
       app_id: "git",
       app_secret: "git",
       args: {
         client_options: {
           site: "https://oauth.ddev.site",
           user_info_url: "/oauth/v1/userinfo",
           authorize_url: "/oauth/authorize",
           token_url: "/oauth/token"
         },
         user_response_structure: {
           root_path: [],
           id_path: ["sub"],
           attributes: {
             email: "email",
             name: "name"
           }
         },
         authorize_params: {
           scope: "oauth2_access_to_profile_information"
         },
         strategy_class: "OmniAuth::Strategies::OAuth2Generic"
       }
     }
    ]
    
  • Status changed to Needs work about 1 year ago
  • First commit to issue fork.
  • Pipeline finished with Success
    11 months ago
    #196588
  • πŸ‡¨πŸ‡­Switzerland znerol

    Rebased 3257293-registered-claims-6.0.x for 6.0.0-beta6.

  • πŸ‡©πŸ‡°Denmark xen

    This issue is two years old and people are starting to maintain MRs to patch from. Isn't it about time it gets merged?

  • πŸ‡³πŸ‡±Netherlands bojan_dev

    I'm happy to merge it, but the MR's are still missing test coverage, so feel free to contribute.

  • πŸ‡©πŸ‡°Denmark xen

    I think the problem is that those most interested in getting this merged lack the required insight to write proper tests.

    Where does one see that "missing test coverage"?

  • πŸ‡³πŸ‡±Netherlands bojan_dev

    See comments from bradjones1: #6, #8 and #23.

    I'm pretty jammed with work, so anyone able to write tests will be welcome.

  • πŸ‡©πŸ‡°Denmark ras-ben Copenhagen

    Adding patch file, for use in composer.json.
    It is made from https://git.drupalcode.org/project/simple_oauth/-/merge_requests/66.patch

  • πŸ‡©πŸ‡°Denmark ras-ben Copenhagen
  • First commit to issue fork.
  • Pipeline finished with Failed
    7 months ago
    Total: 254s
    #293264
  • πŸ‡³πŸ‡±Netherlands idebr

    Added a test for the happy path for a request with a scope 'openid'

  • Pipeline finished with Failed
    7 months ago
    Total: 207s
    #293288
  • πŸ‡¨πŸ‡¦Canada kiwad

    Tested latest MR with a drupal site site as identity provider, simple oauth 6.x and another site using openid_connect

    The MR works well for me.

  • πŸ‡³πŸ‡±Netherlands idebr
  • Pipeline finished with Failed
    7 months ago
    Total: 2081s
    #299700
  • Pipeline finished with Success
    7 months ago
    Total: 365s
    #300013
  • Pipeline finished with Success
    7 months ago
    Total: 242s
    #302755
  • πŸ‡³πŸ‡±Netherlands bojan_dev

    Remaining task (for 5.2.x): copy the Kernel tests from MR !66 to !64.

  • πŸ‡³πŸ‡±Netherlands idebr
  • πŸ‡ΊπŸ‡¦Ukraine chesn0k Ukraine, Odessa

    This bad commit is not compatible with lcobucci/jwt version 5 and above because Lcobucci\JWT\Token\Builder is immutable

    All calls like
    $builder->withClaim($claim_name, $value);

    should be rewritten to
    $builder = $builder->withClaim($claim_name, $value);

  • πŸ‡³πŸ‡±Netherlands idebr

    @chesn0k The code is tested automatically with lcobucci/jwt (5.4.0), see https://git.drupalcode.org/project/simple_oauth/-/jobs/3144336
    Can you post the exact error message?

    Since this issue is already available in the latest release, I suggest creating a new issue.

  • πŸ‡ΊπŸ‡¦Ukraine chesn0k Ukraine, Odessa

    This won’t cause critical errors, but some of the payload might be lost, which could break client-side authorization.

    Ok, I'll open a new issue for this.

Production build 0.71.5 2024