unexpected ID Token "nonce" claim value

Open
#7,313 12 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
nodejs, typescript

Research direction

Start with @auth/core/lib/oauth/callback.js and the processAuthorizationCodeOpenIDResponse call shown in the stack trace, then compare the working @auth/core@0.5.1 patch with the @auth/core@0.6.0 behavior. Reproduce with the linked SvelteKit Cognito sample using PKCE and nonce checks; done means the callback accepts the expected nonce without the OperationProcessingError.

Written by the indexing model from the issue text.

Description

bug providers
Provider type

Cognito

Environment

System:
OS: macOS 13.3.1
CPU: (10) arm64 Apple M1 Max
Memory: 153.55 MB / 32.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 19.9.0 - /opt/homebrew/bin/node
npm: 9.6.3 - /opt/homebrew/bin/npm
Browsers:
Chrome: 112.0.5615.121
Firefox: 101.0
Safari: 16.4

Reproduction URL

https://github.com/half2me/sveltekit-authjs-houdini

Describe the issue

I'm using SvelteKit with Auth.js using the Cognito provider with pcke and nonce checks.

Cognito({
  ...
  checks: ['pkce', 'nonce']
})

After logging in, when being redirected to the my site, I get this error:

[auth][error][CallbackRouteError]: Read more at https://errors.authjs.dev#callbackrouteerror
[auth][cause]: OperationProcessingError: unexpected ID Token "nonce" claim value
    at Module.processAuthorizationCodeOpenIDResponse (file:///Users/halftome/sveltekit-authjs-houdini/node_modules/oauth4webapi/build/index.js:1038:23)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async handleOAuth (file:///Users/halftome/sveltekit-authjs-houdini/node_modules/@auth/sveltekit/node_modules/@auth/core/lib/oauth/callback.js:79:24)
    at async Module.callback (file:///Users/halftome/sveltekit-authjs-houdini/node_modules/@auth/sveltekit/node_modules/@auth/core/lib/routes/callback.js:14:41)
    at async AuthInternal (file:///Users/halftome/sveltekit-authjs-houdini/node_modules/@auth/sveltekit/node_modules/@auth/core/lib/index.js:64:38)
    at async Proxy.Auth (file:///Users/halftome/sveltekit-authjs-houdini/node_modules/@auth/sveltekit/node_modules/@auth/core/index.js:100:30)
    at async Module.respond (/node_modules/@sveltejs/kit/src/runtime/server/respond.js:257:20)
    at async file:///Users/halftome/sveltekit-authjs-houdini/node_modules/@sveltejs/kit/src/exports/vite/dev/index.js:513:22
[auth][details]: {
  "provider": "cognito"
}
How to reproduce

I have a sample repo attached showing the issue. I've just updated to @auth/core@0.6.0.
Previously I had this issue fixed by using @auth/core@0.5.1, and applying this patch:

--- node_modules/@auth/core/lib/oauth/callback.js	2023-03-28 16:30:20
+++ node_modules/@auth/core/lib/oauth/callback.js	2023-04-17 14:11:07
@@ -76,7 +76,8 @@
     let profile = {};
     let tokens;
     if (provider.type === "oidc") {
-        const result = await o.processAuthorizationCodeOpenIDResponse(as, client, codeGrantResponse);
+        const result = await o.processAuthorizationCodeOpenIDResponse(as, client, codeGrantResponse, nonce?.value ??
+o.expectNoNonce);
         if (o.isOAuth2Error(result)) {
             console.log("error", result);
             throw new Error("TODO: Handle OIDC response body error");

You can see the working version at this commit: https://github.com/half2me/sveltekit-authjs-houdini/tree/a3f19a03c79e8b2e20a06c6acacb240ac434d8c3

After updating to the new version, I'm getting the same error I used to have before.

Expected behavior

nonce value was specified as a check, so I'd expect it to work.

Dominant language
TypeScript
Stars
28.4k
Forks
4k
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from nextauthjs/next-auth

All issues in nextauthjs/next-auth

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.