Allow to retrieve clientSecret from an async function #1940

Open
opened 2026-03-13 09:13:53 -05:00 by GiteaMirror · 5 comments
Owner

Originally created by @belgattitude on GitHub (Sep 16, 2025).

Is this suited for github?

  • Yes, this is suited for github

I couldn't find any way to refresh the clientSecret.

For example in our entra configuration, we use the clientSecret from our azure keyvault. Those secrets will automatically by rotated (max age 90 ays, rotation 45 days)

export const auth = createBetterAuth({
  db: dbBaseAuth,
  socialProviders: {
    microsoft: {
      clientId: serverEnv.AUTH_ENTRA_CLIENT_ID!,
      tenantId: serverEnv.AUTH_ENTRA_CLIENT_TENANT_ID!,
      authority: serverEnv.AUTH_ENTRA_AUTHORITY,
      prompt: 'select_account', 
      // 👉 On first run -> get the secret from the keyvault (async with @azure/keyvault-secrets)
      clientSecret:  await getEntraSecretFromKeyvault(),
    },
  },
});

Over a period of time (90days in this example) this secret will be disabled. The only way to get the refreshed one, is to restart the application server.

Describe the solution you'd like

I'd like the have the possibility to set the clientSecret or to allow the configuration to support an async function that get the token (can be lru-ttl-cached for example)

Describe alternatives you've considered

For now there's no urgency, cause everytime the app is restarted a new token is retrieved.

Additional context

No response

Originally created by @belgattitude on GitHub (Sep 16, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### Is your feature request related to a problem? Please describe. I couldn't find any way to refresh the clientSecret. For example in our entra configuration, we use the clientSecret from our azure keyvault. Those secrets will automatically by rotated (max age 90 ays, rotation 45 days) ```typescript export const auth = createBetterAuth({ db: dbBaseAuth, socialProviders: { microsoft: { clientId: serverEnv.AUTH_ENTRA_CLIENT_ID!, tenantId: serverEnv.AUTH_ENTRA_CLIENT_TENANT_ID!, authority: serverEnv.AUTH_ENTRA_AUTHORITY, prompt: 'select_account', // 👉 On first run -> get the secret from the keyvault (async with @azure/keyvault-secrets) clientSecret: await getEntraSecretFromKeyvault(), }, }, }); ``` Over a period of time (90days in this example) this secret will be disabled. The only way to get the refreshed one, is to restart the application server. ### Describe the solution you'd like I'd like the have the possibility to set the clientSecret or to allow the configuration to support an async function that get the token (can be lru-ttl-cached for example) ### Describe alternatives you've considered For now there's no urgency, cause everytime the app is restarted a new token is retrieved. ### Additional context _No response_
GiteaMirror added the enhancement label 2026-03-13 09:13:53 -05:00
Author
Owner

@himself65 commented on GitHub (Sep 18, 2025):

lazy loading the social providers is a good idea

@himself65 commented on GitHub (Sep 18, 2025): lazy loading the social providers is a good idea
Author
Owner

@DustinMoriarty commented on GitHub (Oct 22, 2025):

This would also prevent having to provide a placeholder secret at build time. I think it would be a good idea for all of the primitive type values in the configuration to support callbacks.

@DustinMoriarty commented on GitHub (Oct 22, 2025): This would also prevent having to provide a placeholder secret at build time. I think it would be a good idea for all of the primitive type values in the configuration to support callbacks.
Author
Owner

@dosubot[bot] commented on GitHub (Jan 21, 2026):

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

Issue Summary:

  • You requested support for asynchronously retrieving the clientSecret to enable automatic secret rotation without app restarts.
  • The idea includes using an async function with caching for dynamic refresh of secrets.
  • Other community members have expressed support, highlighting benefits like lazy loading social providers and avoiding placeholder secrets at build time.
  • There was also a proposal to extend async callback support to all primitive config values for greater flexibility.
  • The issue remains unresolved with no recent updates.

Next Steps:

  • Please let me know if this feature is still relevant to the latest version of better-auth by commenting on this issue.
  • If I don’t hear back within 7 days, the issue will be automatically closed.

Thanks for your understanding and contribution!

@dosubot[bot] commented on GitHub (Jan 21, 2026): Hi, @belgattitude. 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 requested support for asynchronously retrieving the clientSecret to enable automatic secret rotation without app restarts. - The idea includes using an async function with caching for dynamic refresh of secrets. - Other community members have expressed support, highlighting benefits like lazy loading social providers and avoiding placeholder secrets at build time. - There was also a proposal to extend async callback support to all primitive config values for greater flexibility. - The issue remains unresolved with no recent updates. **Next Steps:** - Please let me know if this feature is still relevant to the latest version of better-auth by commenting on this issue. - If I don’t hear back within 7 days, the issue will be automatically closed. Thanks for your understanding and contribution!
Author
Owner

@belgattitude commented on GitHub (Jan 28, 2026):

Still relevant in my humble opinion

Can you reopen ?

@belgattitude commented on GitHub (Jan 28, 2026): Still relevant in my humble opinion Can you reopen ?
Author
Owner

@dosubot[bot] commented on GitHub (Jan 28, 2026):

@Bekacru The user belgattitude has indicated that this issue is still relevant and has requested it to be reopened. Could you please take a look and assist?

@dosubot[bot] commented on GitHub (Jan 28, 2026): @Bekacru The user belgattitude has indicated that this issue is still relevant and has requested it to be reopened. Could you please take a look and assist?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#1940