Apikey without user #1988

Closed
opened 2026-03-13 09:19:09 -05:00 by GiteaMirror · 4 comments
Owner

Originally created by @benjaminpreiss on GitHub (Sep 21, 2025).

Is this suited for github?

  • Yes, this is suited for github

When developing a betterAuth plugin, I came across the need to interact with the api.
Currently, this requires one to create a user with the admin role, which requires passing an email.

For server-to-server interactions or for a plugin, this doesn't make a lot of sense, I feel? I would have to make up an email address for that user, which doesnt feel clean. Wouldn't it make more sense to not tie API keys to users?

Also, as I mentioned in another issue, the plugins currently don't have an onInit method available, which would allow to use the auth instance to do some "provisioning", e.g. to set up an api key.

Describe the solution you'd like

Make API keys independent of users.
Add an onInit method to the plugin interface.

Describe alternatives you've considered

Using the anonymous plugin, setting up a user and then creating an API key.

Additional context

No response

Originally created by @benjaminpreiss on GitHub (Sep 21, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### Is your feature request related to a problem? Please describe. When developing a betterAuth plugin, I came across the need to interact with the api. Currently, this requires one to create a user with the admin role, which requires passing an email. For server-to-server interactions or for a plugin, this doesn't make a lot of sense, I feel? I would have to make up an email address for that user, which doesnt feel clean. Wouldn't it make more sense to not tie API keys to users? Also, as I mentioned in another issue, the plugins currently don't have an `onInit` method available, which would allow to use the auth instance to do some "provisioning", e.g. to set up an api key. ### Describe the solution you'd like Make API keys independent of users. Add an `onInit` method to the plugin interface. ### Describe alternatives you've considered Using the `anonymous` plugin, setting up a user and then creating an API key. ### Additional context _No response_
GiteaMirror added the staleenhancementplugin labels 2026-03-13 09:19:09 -05:00
Author
Owner

@ping-maxwell commented on GitHub (Nov 3, 2025):

I feel like this is more of an m2m authorization issue, our api-key plugins at minimum needs an entity.

I do believe there is an issue already open asking for m2m support.

@ping-maxwell commented on GitHub (Nov 3, 2025): I feel like this is more of an m2m authorization issue, our api-key plugins at minimum needs __*an*__ entity. I do believe there is an issue already open asking for m2m support.
Author
Owner

@better-auth-agent[bot] commented on GitHub (Nov 3, 2025):

(tag @better-auth-agent) Could you please clarify if you're looking for guidance on how to approach handling this m2m authorization scenario where the API key must be associated with an entity? For instance, one next step could be exploring whether creating a dedicated system entity (separate from the typical user model) for machine-to-machine interactions might resolve your issue. This would let you provision API keys without tying them to a standard user, aligning with your requirement for cleaner server-to-server integrations [1]. Have you already considered a design pattern similar to service accounts, or would you need more details on that approach?

DiagramDiscordGitHub

Diagram Join Star

@better-auth-agent[bot] commented on GitHub (Nov 3, 2025): (tag @better-auth-agent) Could you please clarify if you're looking for guidance on how to approach handling this m2m authorization scenario where the API key must be associated with an entity? For instance, one next step could be exploring whether creating a dedicated system entity (separate from the typical user model) for machine-to-machine interactions might resolve your issue. This would let you provision API keys without tying them to a standard user, aligning with your requirement for cleaner server-to-server integrations [[1]](https://github.com/better-auth/better-auth/issues/4797). Have you already considered a design pattern similar to service accounts, or would you need more details on that approach? <!-- bot:webhook reply v1 --> [Diagram](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) • [Discord](https://discord.gg/better-auth) • [GitHub](https://github.com/better-auth/better-auth) [![Diagram](https://img.shields.io/badge/Diagram-2b3137?style=flat-square)](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) [![Join](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/better-auth) [![Star](https://img.shields.io/badge/star-181717?logo=github&logoColor=white&style=flat-square)](https://github.com/better-auth/better-auth)
Author
Owner

@better-auth-agent[bot] commented on GitHub (Nov 3, 2025):

Thanks for sharing your thoughts! You're absolutely right that our current API-key design requires an associated entity, which creates challenges for pure machine-to-machine use cases. There's an open discussion about enhancing M2M support so that API keys could be independent of users and allow for plugin provisioning via an onInit method [1]. Until we implement those changes, a common workaround is to use the anonymous plugin or set up a dedicated service account to act as the required entity.

Does that help address your needs, or would you like to explore any alternative approaches in the meantime?
tag @better-auth-agent

DiagramDiscordGitHub

Diagram Join Star

@better-auth-agent[bot] commented on GitHub (Nov 3, 2025): Thanks for sharing your thoughts! You're absolutely right that our current API-key design requires an associated entity, which creates challenges for pure machine-to-machine use cases. There's an open discussion about enhancing M2M support so that API keys could be independent of users and allow for plugin provisioning via an onInit method [[1]](https://github.com/better-auth/better-auth/issues/4797). Until we implement those changes, a common workaround is to use the anonymous plugin or set up a dedicated service account to act as the required entity. Does that help address your needs, or would you like to explore any alternative approaches in the meantime? tag @better-auth-agent <!-- bot:webhook reply v1 --> [Diagram](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) • [Discord](https://discord.gg/better-auth) • [GitHub](https://github.com/better-auth/better-auth) [![Diagram](https://img.shields.io/badge/Diagram-2b3137?style=flat-square)](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) [![Join](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/better-auth) [![Star](https://img.shields.io/badge/star-181717?logo=github&logoColor=white&style=flat-square)](https://github.com/better-auth/better-auth)
Author
Owner

@dosubot[bot] commented on GitHub (Feb 2, 2026):

Hi, @benjaminpreiss. 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 making API keys independent of users to better support server-to-server (machine-to-machine) interactions and plugin initialization via an onInit method.
  • Maintainers acknowledged this as a machine-to-machine authorization issue and referenced an ongoing discussion about enhancing m2m support.
  • Currently, API keys must be tied to an entity, with common workarounds including anonymous plugins or dedicated service accounts.
  • The team is open to exploring alternative approaches but has not yet resolved this request.

Next Steps:

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

Thank you for your understanding and contribution!

@dosubot[bot] commented on GitHub (Feb 2, 2026): Hi, @benjaminpreiss. 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 making API keys independent of users to better support server-to-server (machine-to-machine) interactions and plugin initialization via an onInit method. - Maintainers acknowledged this as a machine-to-machine authorization issue and referenced an ongoing discussion about enhancing m2m support. - Currently, API keys must be tied to an entity, with common workarounds including anonymous plugins or dedicated service accounts. - The team is open to exploring alternative approaches but has not yet resolved this request. **Next Steps:** - Please let me know if this issue is still relevant to the latest version of better-auth by commenting here to keep the discussion open. - If I do not hear back within 7 days, I will automatically close this issue. Thank you for your understanding and contribution!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#1988