[PR #2912] [CLOSED] fix: Use jwt plugin and RSA instead of HS256 for oidcProvider #12799

Closed
opened 2026-04-13 08:36:08 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/2912
Author: @BadPirate
Created: 6/5/2025
Status: Closed

Base: mainHead: fix/2726-oidc-provider-rsa


📝 Commits (7)

  • 635a296 fix: Use jwt plugin and RSA instead of HS256 for oidcProvider
  • da72ad9 Merge branch 'main' into fix/2726-oidc-provider-rsa
  • 6c8aa26 Type check / assertion
  • d62c5ba pnpm format --fix
  • a7c1c42 key or keylike
  • 3379f4f chore: lint
  • 4f3cafc Merge branch 'main' into fix/2726-oidc-provider-rsa

📊 Changes

3 files changed (+110 additions, -3 deletions)

View changed files

📝 docs/content/docs/plugins/oidc-provider.mdx (+21 -3)
📝 packages/better-auth/src/plugins/oidc-provider/index.ts (+77 -0)
📝 packages/better-auth/src/plugins/oidc-provider/types.ts (+12 -0)

📄 Description

Current implementation for jwks in oidcProvider is incomplete / broken it ignores jwt plugin and uses HS256, which is not normally a supported algorithm for jwks.

Since changing it to the right algorithm would break any existing implementations, I added a flag to oidcProvider for "useJWTPlugin" if that flag is set to true, and jwt plugin is setup, oidcProvider will use the same key as the one reported in jwks endpoint from jwt generating tokens that correctly validate.

Resolves #2726

Tested with config:

jwt({
  jwks: {
    keyPairConfig: {
      alg: 'RS256',
      modulusLength: 2048,
    },
  },
  ...
  }),
  oidcProvider({
    useJWTPlugin: true,
    loginPage: '/auth/signin',
    ...
  })

Created a jwt for a genericOauth, validated header:

{
  "alg": "RS256",
  "kid": "cA1t6gJISVPhQBIoYbNnrIPx3Bo4wNao"
}

Verified signature using the api/auth/jwks endpoint payload and jwt.io


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/2912 **Author:** [@BadPirate](https://github.com/BadPirate) **Created:** 6/5/2025 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/2726-oidc-provider-rsa` --- ### 📝 Commits (7) - [`635a296`](https://github.com/better-auth/better-auth/commit/635a296d9ecbe526c90d7334e6cea963e30da9ce) fix: Use jwt plugin and RSA instead of HS256 for oidcProvider - [`da72ad9`](https://github.com/better-auth/better-auth/commit/da72ad9522e7e6c5984061f36f56c0e10c7f7960) Merge branch 'main' into fix/2726-oidc-provider-rsa - [`6c8aa26`](https://github.com/better-auth/better-auth/commit/6c8aa268a434d6c320bdecb906628bbd94d35942) Type check / assertion - [`d62c5ba`](https://github.com/better-auth/better-auth/commit/d62c5ba073ce34f5a603a16c1201011f679b179b) pnpm format --fix - [`a7c1c42`](https://github.com/better-auth/better-auth/commit/a7c1c42ee5672c88fc7812915c341d124fe853e3) key or keylike - [`3379f4f`](https://github.com/better-auth/better-auth/commit/3379f4f946cdc69f4539119c03c9838941104c5c) chore: lint - [`4f3cafc`](https://github.com/better-auth/better-auth/commit/4f3cafcc955accea9020ab941dac56867307b80d) Merge branch 'main' into fix/2726-oidc-provider-rsa ### 📊 Changes **3 files changed** (+110 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `docs/content/docs/plugins/oidc-provider.mdx` (+21 -3) 📝 `packages/better-auth/src/plugins/oidc-provider/index.ts` (+77 -0) 📝 `packages/better-auth/src/plugins/oidc-provider/types.ts` (+12 -0) </details> ### 📄 Description Current implementation for jwks in oidcProvider is incomplete / broken it ignores jwt plugin and uses HS256, which is not normally a supported algorithm for jwks. Since changing it to the right algorithm would break any existing implementations, I added a flag to oidcProvider for "useJWTPlugin" if that flag is set to true, and jwt plugin is setup, oidcProvider will use the same key as the one reported in jwks endpoint from jwt generating tokens that correctly validate. Resolves #2726 Tested with config: ```js jwt({ jwks: { keyPairConfig: { alg: 'RS256', modulusLength: 2048, }, }, ... }), oidcProvider({ useJWTPlugin: true, loginPage: '/auth/signin', ... }) ``` Created a jwt for a genericOauth, validated header: ``` { "alg": "RS256", "kid": "cA1t6gJISVPhQBIoYbNnrIPx3Bo4wNao" } ``` Verified signature using the `api/auth/jwks` endpoint payload and jwt.io --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-13 08:36:08 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#12799