Needs review
Project:
Simple OAuth (OAuth2) & OpenID Connect
Version:
6.1.x-dev
Component:
OpenID Connect
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
13 Nov 2020 at 18:15 UTC
Updated:
18 Aug 2026 at 16:40 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
e0ipsoThanks for opening this. Is there any chance you can provide a patch for this?
🙏
Comment #3
kamalw commentedI am sorry I am new to this protocol and simple_oauth. It sounds simple but I am not sure if it is actually a simple task or an elaborate one.
Comment #4
e0ipsoNo worries, I am sure that if this affects many people we will get a patch eventually.
Thanks for opening the issue in the first place.
Comment #5
bradjones1Per https://openid.net/specs/openid-connect-basic-1_0.html#RequestParameters this is optional:
"Use of the nonce is OPTIONAL when using the code flow."
So this appears to be a feature request; I also was only tangentially involved in the OIDC implementation issue so I'm not sure if this was considered and not implemented for any particular reason. It might also be unnecessary given other mitigating controls, I'd have to read the spec closer.
https://git.drupalcode.org/search?search=nonce&group_id=2&project_id=523...
Comment #6
pandepoulus commentedHello, i would like to point that nonce is optional for the openid client implementation (client libraries do not need to provide a nonce parameter) but as the documentation clearly says it MUST return a token when the nonce is present.
Client libraries which are openid compliant are not compatible because are providing the nonce token, like angular-auth-oidc-client.
Kind regards and many thanks for your module.
Comment #7
e0ipsoAh! Thanks for pointing this out. You are right!
Is there any chance either of you (@kamalw or @Pandepoulus) can work on a patch for this feature? Otherwise there is a big chance this will not get implemented, as we are spread too thin already and don't have a use case for our projects.
Comment #8
bradjones1Comment #9
bradjones1Comment #10
bradjones1Comment #11
pandepoulus commentedHello, i did spend some time reading the spec, but i am quite noob to all this auth flow. If i didn't missunderstand, the only thing required is to take the "nonce" parameter in the request and sign it as a claim in the signed token_id provided.
So i think it might be done just adding the token from the request at hook_simple_oauth_private_claims_alter.
If you think that solution is ok i could provide the patch.
Kind regards.
Comment #12
bradjones1Thanks for volunteering to help. I think in general, you're correct - it just needs to be included in the response to help protect against replay attacks. However I don't think the hook is necessary, since the module itself is providing the implementation.
Comment #13
jkdev commentedThe nonce should be included as claim in the id token. (not the access token)
So use of hook_simple_oauth_private_claims_alter will not help.
The correct place is: web/modules/contrib/simple_oauth/src/Normalizer/UserClaimsNormalizer.php:88
So we have:
1. to store somewhere the nonce received at the request of: /authorize
2. to return the nonce as a new claim.
Attached a patch - fully working, but obviously need more testing.
Mind that in a lack of better idea, where to store the nonce, it stores it with drupal cache (expired in hour).
Let me know your thoughts,
Comment #14
bradjones1Use DI
I don't think this qualifies as securely binding the nonce to the client and user-agent. See https://datatracker.ietf.org/doc/html/draft-ietf-oauth-security-topics#s...
More specifically to the last point, I think storing the nonce on the session would be sufficient/better than caching it.
Comment #15
bradjones1Comment #16
jkdev commentedThis cannot be stored in session, since the user is not logged in, in terms of session cookie when passing token.
I repeat. I'm conscious that cache is not the most appropriate place to store the nonce, and we are open to suggestions.
One would argue that the most logical place would be the token entity itself in the DB.
I'm willing to make some progress on this, but would need some guidance.
Comment #17
bradjones1Anonymous users may still have sessions. E.g., how Commerce handles shopping carts for anonymous customers.
Comment #18
jkdev commentedLet me shed some more light how you guys (the developers of this module) built this:
Background: The user is at some mobile app, and want to interact with Drupal site, but are unable to read HTML, so the data flow rely on API (json format). In order to make requests as a logged-in user, the user must obtain a token instead of the cookie based authentication mechanism built-in the Drupal. But the process must kick in with web technologies, so there is two requests.
The e-commerce solutions rely on the fact that calls to the cart page is still coming from a web browser.
In our scenario, the requests comes from mobile device that simply doesn't read/write cookies.
meaning that we have no session whatsoever between the two requests.
Having said the above, I would like to iterate, that to my opinion, if it's possible to change the schema of the token entity, to hold one more property: nonce.
Comment #19
jeroen_vreuls commentedI also think storing the nonce should be handled differently. Having said that, this patch has helped us with getting the nonce in the ID token.
But the current patch will not add the nonce when you are redirected to the authorization form to give permission for the client. The attached patch solves that.
Comment #20
rodrigoaguileraI updated the patch for 6.0.x
As said before, there must be a better way to store the nonce
Comment #22
freelockUpdating the target version - the MR I just created is against 6.0.x instead of 6.1.x.
Comment #24
freelockOk, went through this with GPT Sol, came up with a better flow that is part of the authorization flow, and eliminates a race from the previous patch version.
I'm going to test this on a production instance, to use as an IDP for a Headscale (Tailscale) network, will report back if this works...
Comment #25
freelockOk, tests pass now, and cleaned up the phpstan issues...
Comment #26
freelockConfirmed that this is working for us now, with Headscale as a consumer -- without this patch, you cannot authenticate against Drupal/Simple_OAuth. With it, it appears to work fine!