[PR #5431] feat(sso): add option to encrypt oidc client secret at rest #6003

Open
opened 2026-03-13 12:44:19 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/5431
Author: @tnkuehne
Created: 10/20/2025
Status: 🔄 Open

Base: canaryHead: feat/encrypt-sso-oidc-client-secret-at-rest


📝 Commits (8)

  • 0fe42d3 feat(sso): add option to encrypt client secret at rest
  • 9661705 chore: add tests
  • 40ddb9b chore: add docs
  • 06f368c chore: catch decryption errors
  • e31cd7f chore: make api design similar to other plugins
  • fbfed00 Merge branch 'canary' into feat/encrypt-sso-oidc-client-secret-at-rest
  • 771746a chore: fix typo in the docs
  • ac5b45d chore: address comments

📊 Changes

3 files changed (+458 additions, -125 deletions)

View changed files

📝 docs/content/docs/plugins/sso.mdx (+76 -13)
📝 packages/sso/src/index.ts (+97 -13)
📝 packages/sso/src/oidc.test.ts (+285 -99)

📄 Description

Closes #4291

Currently the client secret of any registered oidc provider is saved as plain text in the database.

This PR changes this by encrypting the client secret with BETTER_AUTH_SECRET at rest.


Summary by cubic

Adds a configurable way to store OIDC client secrets in the SSO plugin. Secrets can be kept plain, encrypted with BETTER_AUTH_SECRET, or encrypted via a custom encryptor; they’re decrypted on read and during sign‑in.

  • New Features

    • Added sso({ storeSecretAs }) with "plain" (default), "encrypted", or custom { encrypt, decrypt }.
    • Encrypt on write and return decrypted clientSecret via API; decryption failures return a clear API error.
    • Updated docs and added tests for encrypted and custom encryptor flows.
  • Migration

    • Migrate existing plaintext secrets before switching storeSecretAs to "encrypted" or a custom encryptor.
    • Restrict access to endpoints that return decrypted clientSecret.

Written for commit ac5b45d6e1. Summary will update on new commits.


🔄 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/5431 **Author:** [@tnkuehne](https://github.com/tnkuehne) **Created:** 10/20/2025 **Status:** 🔄 Open **Base:** `canary` ← **Head:** `feat/encrypt-sso-oidc-client-secret-at-rest` --- ### 📝 Commits (8) - [`0fe42d3`](https://github.com/better-auth/better-auth/commit/0fe42d3c836d30c8d7e73846b8f1a59f56125ff4) feat(sso): add option to encrypt client secret at rest - [`9661705`](https://github.com/better-auth/better-auth/commit/966170502003d7b68ac27c83c29a580979f50660) chore: add tests - [`40ddb9b`](https://github.com/better-auth/better-auth/commit/40ddb9b883ab435f2a855907e11bc17f44f0cdd3) chore: add docs - [`06f368c`](https://github.com/better-auth/better-auth/commit/06f368c37aac95d7a094da78b309aab27b2e778e) chore: catch decryption errors - [`e31cd7f`](https://github.com/better-auth/better-auth/commit/e31cd7f2addcc594f5173ce2fdfc32a15e90d406) chore: make api design similar to other plugins - [`fbfed00`](https://github.com/better-auth/better-auth/commit/fbfed00bd8534d1e0ff29c67273b8974248f79e4) Merge branch 'canary' into feat/encrypt-sso-oidc-client-secret-at-rest - [`771746a`](https://github.com/better-auth/better-auth/commit/771746a7385905374d6a42e0ea6e1cfa9b534e6f) chore: fix typo in the docs - [`ac5b45d`](https://github.com/better-auth/better-auth/commit/ac5b45d6e18cb579c0f1103e58c79ce2f390acab) chore: address comments ### 📊 Changes **3 files changed** (+458 additions, -125 deletions) <details> <summary>View changed files</summary> 📝 `docs/content/docs/plugins/sso.mdx` (+76 -13) 📝 `packages/sso/src/index.ts` (+97 -13) 📝 `packages/sso/src/oidc.test.ts` (+285 -99) </details> ### 📄 Description Closes #4291 Currently the client secret of any registered oidc provider is saved as plain text in the database. This PR changes this by encrypting the client secret with BETTER_AUTH_SECRET at rest. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Adds a configurable way to store OIDC client secrets in the SSO plugin. Secrets can be kept plain, encrypted with BETTER_AUTH_SECRET, or encrypted via a custom encryptor; they’re decrypted on read and during sign‑in. - **New Features** - Added sso({ storeSecretAs }) with "plain" (default), "encrypted", or custom { encrypt, decrypt }. - Encrypt on write and return decrypted clientSecret via API; decryption failures return a clear API error. - Updated docs and added tests for encrypted and custom encryptor flows. - **Migration** - Migrate existing plaintext secrets before switching storeSecretAs to "encrypted" or a custom encryptor. - Restrict access to endpoints that return decrypted clientSecret. <sup>Written for commit ac5b45d6e18cb579c0f1103e58c79ce2f390acab. Summary will update on new commits.</sup> <!-- End of auto-generated description by cubic. --> --- <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-03-13 12:44:19 -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#6003