Skip to content

Commit c46c81d

Browse files
f0sselblink-so[bot]
authored andcommitted
fix: Make backendUrl explicit requirement in appConfig
- Backend no longer sends backendUrl in API response - Frontend only uses appConfig.oauth.backendUrl (no fallback) - OAuth button won't work unless backendUrl is explicitly configured - Validation is skipped if backendUrl is not set - Updated example configs to include required backendUrl
1 parent f029d75 commit c46c81d

File tree

4 files changed

+17
-7
lines changed

4 files changed

+17
-7
lines changed

packages/app/src/components/catalog/EntityPage.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ const coderAppConfig: CoderAppConfig = {
136136
accessUrl: 'https://dev.coder.com',
137137
},
138138

139+
oauth: {
140+
backendUrl: 'http://localhost:7007',
141+
},
142+
139143
workspaces: {
140144
defaultTemplateName: 'devcontainers',
141145
defaultMode: 'manual',

plugins/backstage-plugin-coder-backend/src/service/router.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,9 @@ export async function createRouter(
2424
const coderConfig = config.getOptionalConfig('coder');
2525

2626
const clientId = coderConfig?.getString('oauth.clientId') || 'backstage';
27-
const backendUrl = `${req.protocol}://${req.get('host')}`;
2827

2928
res.json({
3029
clientId,
31-
backendUrl,
3230
});
3331
} catch (error) {
3432
logger.error('Failed to get OAuth config', error);

plugins/backstage-plugin-coder/dev/DevPage.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ const appConfig: CoderAppConfig = {
2323
accessUrl: 'https://dev.coder.com',
2424
},
2525

26+
oauth: {
27+
backendUrl: 'http://localhost:7007',
28+
},
29+
2630
workspaces: {
2731
defaultTemplateName: 'devcontainers',
2832
defaultMode: 'manual',

plugins/backstage-plugin-coder/src/components/CoderAuthForm/CoderAuthInputForm.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import SyncIcon from '@material-ui/icons/Sync';
1616

1717
type OAuthConfig = {
1818
clientId: string;
19-
backendUrl: string;
2019
};
2120

2221
const useStyles = makeStyles(theme => ({
@@ -108,7 +107,7 @@ export const CoderAuthInputForm = () => {
108107
useEffect(() => {
109108
const handleOAuthMessage = (event: MessageEvent) => {
110109
// Verify the message is from our OAuth callback backend
111-
const backendUrl = oauthConfig?.backendUrl || appConfig.oauth?.backendUrl;
110+
const backendUrl = appConfig.oauth?.backendUrl;
112111

113112
// If backendUrl is configured, verify the origin matches
114113
if (backendUrl) {
@@ -128,7 +127,7 @@ export const CoderAuthInputForm = () => {
128127

129128
window.addEventListener('message', handleOAuthMessage);
130129
return () => window.removeEventListener('message', handleOAuthMessage);
131-
}, [registerNewToken, oauthConfig, appConfig.oauth?.backendUrl]);
130+
}, [registerNewToken, appConfig.oauth?.backendUrl]);
132131

133132
const onSubmit = (event: FormEvent<HTMLFormElement>) => {
134133
event.preventDefault();
@@ -141,9 +140,14 @@ export const CoderAuthInputForm = () => {
141140

142141
const handleOAuthLogin = () => {
143142
const authUrl = `${appConfig.deployment.accessUrl}/oauth2/authorize`;
144-
// Use fetched config with fallback to appConfig
145143
const clientId = oauthConfig?.clientId || appConfig.oauth?.clientId || 'backstage';
146-
const backendUrl = oauthConfig?.backendUrl || appConfig.oauth?.backendUrl || `${window.location.protocol}//${window.location.hostname}:7007`;
144+
const backendUrl = appConfig.oauth?.backendUrl;
145+
146+
if (!backendUrl) {
147+
console.error('OAuth backendUrl not configured in appConfig.oauth.backendUrl');
148+
return;
149+
}
150+
147151
const redirectUri = `${backendUrl}/api/auth/coder/oauth/callback`;
148152
const state = btoa(JSON.stringify({ returnTo: window.location.pathname }));
149153

0 commit comments

Comments
 (0)