[GH-ISSUE #3071] OIDC Plugin does not set the iss claim in the JWT properly #18092

Closed
opened 2026-04-15 16:27:25 -05:00 by GiteaMirror · 4 comments
Owner

Originally created by @anglinb on GitHub (Jun 18, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/3071

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch better-auth@1.2.8-beta.7 for the project I'm working on.

The OIDC provider does not appropriately set the iss claim in the JWT returned from the oauth2 token endpoint.

Here is the diff that solved my problem:

diff --git a/node_modules/better-auth/dist/plugins/oidc-provider/index.cjs b/node_modules/better-auth/dist/plugins/oidc-provider/index.cjs
index 6baa7fa..55fee0d 100644
--- a/node_modules/better-auth/dist/plugins/oidc-provider/index.cjs
+++ b/node_modules/better-auth/dist/plugins/oidc-provider/index.cjs
@@ -1044,6 +1044,7 @@ const oidcProvider = (options) => {
           };
           const additionalUserClaims = options.getAdditionalUserInfoClaim ? options.getAdditionalUserInfoClaim(user, requestedScopes) : {};
           const idToken = await new jose.SignJWT({
+            iss: ctx.context.baseURL,
             sub: user.id,
             aud: client_id.toString(),
             iat: Date.now(),

This issue body was partially generated by patch-package.

Originally created by @anglinb on GitHub (Jun 18, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/3071 Hi! 👋 Firstly, thanks for your work on this project! 🙂 Today I used [patch-package](https://github.com/ds300/patch-package) to patch `better-auth@1.2.8-beta.7` for the project I'm working on. The OIDC provider does not appropriately set the `iss` claim in the JWT returned from the `oauth2` token endpoint. Here is the diff that solved my problem: ```diff diff --git a/node_modules/better-auth/dist/plugins/oidc-provider/index.cjs b/node_modules/better-auth/dist/plugins/oidc-provider/index.cjs index 6baa7fa..55fee0d 100644 --- a/node_modules/better-auth/dist/plugins/oidc-provider/index.cjs +++ b/node_modules/better-auth/dist/plugins/oidc-provider/index.cjs @@ -1044,6 +1044,7 @@ const oidcProvider = (options) => { }; const additionalUserClaims = options.getAdditionalUserInfoClaim ? options.getAdditionalUserInfoClaim(user, requestedScopes) : {}; const idToken = await new jose.SignJWT({ + iss: ctx.context.baseURL, sub: user.id, aud: client_id.toString(), iat: Date.now(), ``` <em>This issue body was [partially generated by patch-package](https://github.com/ds300/patch-package/issues/296).</em>
GiteaMirror added the lockedbug labels 2026-04-15 16:27:25 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Sep 17, 2025):

Hi, @anglinb. I'm Dosu, and I'm helping the better-auth team manage their backlog and am marking this issue as stale.

Issue Summary:

  • You reported that the OIDC plugin in better-auth@1.2.8-beta.7 was not setting the iss claim in the JWT from the OAuth2 token endpoint.
  • You submitted a patch that adds the iss claim using ctx.context.baseURL.
  • No further comments or activity have been recorded since your patch submission.
  • Your patch resolved the issue by properly setting the iss claim.

Next Steps:

  • Please let us know if this issue is still relevant with the latest version of better-auth by commenting here.
  • If I do not hear back within 7 days, I will automatically close this issue.

Thank you for your understanding and contribution!

<!-- gh-comment-id:3303664208 --> @dosubot[bot] commented on GitHub (Sep 17, 2025): Hi, @anglinb. I'm [Dosu](https://dosu.dev), and I'm helping the better-auth team manage their backlog and am marking this issue as stale. Issue Summary: - You reported that the OIDC plugin in better-auth@1.2.8-beta.7 was not setting the `iss` claim in the JWT from the OAuth2 token endpoint. - You submitted a patch that adds the `iss` claim using `ctx.context.baseURL`. - No further comments or activity have been recorded since your patch submission. - Your patch resolved the issue by properly setting the `iss` claim. Next Steps: - Please let us know if this issue is still relevant with the latest version of better-auth by commenting here. - If I do not hear back within 7 days, I will automatically close this issue. Thank you for your understanding and contribution!
Author
Owner

@anglinb commented on GitHub (Sep 17, 2025):

Yes this is still relevant, we still maintain a patched version for better-auth to work for us.

<!-- gh-comment-id:3303669159 --> @anglinb commented on GitHub (Sep 17, 2025): Yes this is still relevant, we still maintain a patched version for better-auth to work for us.
Author
Owner

@dustintownsend commented on GitHub (Oct 14, 2025):

I ran into this as well and found a "hack" to fix it without having to do a patch-package. There is another issue with the iat being set in ms instead of seconds when using the jwt plugin.

Their is an active PR for a rewrite of this plugin (OAuth 2.1) so I think using a workaround for now is acceptable vs opening a PR to fix them.

In the oidcProvider config there is getAdditionalUserInfoClaim function that gets merged into the token payload before it is signed. In the current code it is the last thing that gets merged (object spread) into the payload so will overwrite other values. Below is what I did to correct the iss value and the iat value.

oidcProvider({
      metadata: {
        issuer: env.AUTH_ISSUER_URL,
      },
      getAdditionalUserInfoClaim: () => {
        return {
          iat: Math.floor(Date.now() / 1000),
          iss: env.AUTH_ISSUER_URL,
        };
      },
}),
<!-- gh-comment-id:3401664114 --> @dustintownsend commented on GitHub (Oct 14, 2025): I ran into this as well and found a "hack" to fix it without having to do a patch-package. There is another issue with the `iat` being set in ms instead of seconds when using the jwt plugin. Their is an active PR for a rewrite of this plugin (OAuth 2.1) so I think using a workaround for now is acceptable vs opening a PR to fix them. In the `oidcProvider` config there is `getAdditionalUserInfoClaim` function that gets merged into the token payload before it is signed. In the current code it is the last thing that gets merged (object spread) into the payload so will overwrite other values. Below is what I did to correct the `iss` value and the `iat` value. ```ts oidcProvider({ metadata: { issuer: env.AUTH_ISSUER_URL, }, getAdditionalUserInfoClaim: () => { return { iat: Math.floor(Date.now() / 1000), iss: env.AUTH_ISSUER_URL, }; }, }), ```
Author
Owner

@dvanmali commented on GitHub (Dec 24, 2025):

Hi all, we released the new OAuth Provider Plugin which fixes the iss claim in the JWT. Feel free to let us know how it works :)

<!-- gh-comment-id:3688549135 --> @dvanmali commented on GitHub (Dec 24, 2025): Hi all, we released the new [OAuth Provider Plugin](https://www.better-auth.com/docs/plugins/oauth-provider) which fixes the `iss` claim in the JWT. Feel free to let us know how it works :)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#18092