Backend authentication module for integrating Coder OAuth2 with Backstage's native authentication system.
Note
This module is designed to work with the @coder/backstage-plugin-coder frontend plugin. It registers Coder as an OAuth2 provider using Backstage's New Backend System.
- Native Backstage auth integration using
authProvidersExtensionPoint - OAuth2 authorization flow for Coder API access
- Automatic user profile fetching from Coder's
/api/v2/users/meendpoint - Session management with token persistence and refresh
- Backstage version 1.24+ with the New Backend System
- A Coder deployment with OAuth2 provider enabled (requires
oauth2experiment flag) - OAuth2 application registered in Coder
-
Install the module in your Backstage backend:
yarn workspace backend add @coder/plugin-auth-backend-module-coder-provider
-
Register the module in your
packages/backend/src/index.ts:// Add the Coder auth provider module backend.add(import('@coder/plugin-auth-backend-module-coder-provider'));
-
Configure Coder deployment in your
app-config.yaml:coder: deployment: accessUrl: https://your-coder-deployment.com
-
Configure OAuth credentials in your
app-config.yaml(use environment variables for production):auth: environment: production providers: coder: production: clientId: ${CODER_OAUTH_CLIENT_ID} clientSecret: ${CODER_OAUTH_CLIENT_SECRET} deploymentUrl: ${CODER_DEPLOYMENT_URL}
[!TIP] For local development, create an
app-config.local.yamlfile (gitignored) with your credentials. -
Create an OAuth2 application in Coder:
- Navigate to your Coder deployment's OAuth2 settings
- Create a new OAuth2 application
- Set the callback URL to:
https://your-backstage-instance.com/api/auth/coder/handler/frame - Replace
your-backstage-instance.comwith your actual Backstage domain - Save the client ID and client secret
For different environments, configure the provider in your app-config files:
auth:
environment: ${AUTH_ENVIRONMENT:-production}
providers:
coder:
production:
clientId: ${CODER_OAUTH_CLIENT_ID}
clientSecret: ${CODER_OAUTH_CLIENT_SECRET}
deploymentUrl: ${CODER_DEPLOYMENT_URL}
development:
clientId: ${CODER_OAUTH_CLIENT_ID}
clientSecret: ${CODER_OAUTH_CLIENT_SECRET}
deploymentUrl: ${CODER_DEPLOYMENT_URL}| Key | Description | Required |
|---|---|---|
clientId |
OAuth2 client ID from Coder | Yes |
clientSecret |
OAuth2 client secret from Coder | Yes |
deploymentUrl |
URL of your Coder deployment | Yes |
Important
The clientSecret is marked as sensitive and will be redacted in logs.
This backend module requires frontend configuration. See the @coder/backstage-plugin-coder README for complete setup instructions.
This module registers Coder as an auth provider. You can use it for:
Resource Access (Default) - Users authenticate to Coder via button in workspace card for API access.
Sign-In Provider (Optional) - Users can sign in to Backstage with Coder for seamless workspace access. Requires adding signIn.resolvers to your auth.providers.coder configuration:
auth:
providers:
coder:
development:
# ... OAuth credentials from steps above
signIn:
resolvers:
- resolver: usernameMatchingUserEntityNameSee the frontend plugin README for SignInPage and UserSettings configuration.
This module replaces the OAuth functionality in @coder/backstage-plugin-coder-backend. If you're only using that plugin for OAuth, you can safely remove it after migrating to this module.
Coder's OAuth2 provider is currently experimental. To enable it:
-
Start Coder with the oauth2 experiment flag:
coder server --experiments oauth2
Or set the environment variable:
export CODER_EXPERIMENTS=oauth2 -
Create an OAuth2 application via the Coder web UI or API:
- Navigate to Deployment Settings → OAuth2 Applications
- Click Create Application
- Set the callback URL to:
https://your-backstage-instance.com/api/auth/coder/handler/frame - Replace
your-backstage-instance.comwith your actual Backstage domain
For more information, see Coder's OAuth2 Provider documentation.
Solution: Ensure auth.providers.coder is configured in your app-config.yaml or app-config.local.yaml.
Solution: Verify your OAuth2 application credentials in Coder match your Backstage configuration.
Solution: Ensure the callback URL in your Coder OAuth2 application settings exactly matches your Backstage instance:
https://your-backstage-instance.com/api/auth/coder/handler/frame
The URL must use HTTPS in production and match your Backstage domain exactly.
Contributions are welcome! Please ensure:
- Code follows the existing style (Prettier, ESLint)
- All tests pass
- New features include tests
- Documentation is updated
See the root LICENSE file for details.