Skip to content

Commit 6e3d722

Browse files
committed
fixes for sso
1 parent de004e3 commit 6e3d722

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

src/resolvers/user.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,19 @@ export default {
108108
const enforcedWorkspace = workspaces.find(w => w.sso?.enabled && w.sso?.enforced);
109109

110110
if (enforcedWorkspace) {
111-
throw new AuthenticationError(
112-
'This workspace requires SSO login. Please use SSO to sign in.'
111+
const error = new AuthenticationError(
112+
'SSO_REQUIRED'
113113
);
114+
115+
/**
116+
* Add workspace info to extensions for frontend
117+
*/
118+
error.extensions = {
119+
code: 'SSO_REQUIRED',
120+
workspaceName: enforcedWorkspace.name,
121+
workspaceId: enforcedWorkspace._id.toString(),
122+
};
123+
throw error;
114124
}
115125

116126
return user.generateTokensPair();

src/sso/saml/controller.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,19 @@ export default class SamlController {
112112
/**
113113
* 4. Generate AuthnRequest
114114
*/
115+
const spEntityId = process.env.SSO_SP_ENTITY_ID || 'NOT_SET';
116+
117+
this.log(
118+
'info',
119+
'Generating SAML AuthnRequest:',
120+
'| Workspace:',
121+
sgr(workspaceId, Effect.ForegroundCyan),
122+
'| SP Entity ID:',
123+
sgr(spEntityId, [Effect.ForegroundMagenta, Effect.Bold]),
124+
'| ACS URL:',
125+
sgr(acsUrl, Effect.ForegroundGray)
126+
);
127+
115128
const { requestId, encodedRequest } = await this.samlService.generateAuthnRequest(
116129
workspaceId,
117130
acsUrl,
@@ -292,11 +305,14 @@ export default class SamlController {
292305
const tokens = await user.generateTokensPair(workspace.sso?.enforced || false);
293306

294307
/**
295-
* 6. Redirect to Garage with tokens
308+
* 6. Redirect to Garage SSO callback page with tokens
309+
* The SSO callback page will save tokens to store and redirect to finalReturnUrl
296310
*/
297-
const frontendUrl = new URL(finalReturnUrl, process.env.GARAGE_URL || 'http://localhost:3000');
311+
const callbackPath = `/login/sso/${workspaceId}`;
312+
const frontendUrl = new URL(callbackPath, process.env.GARAGE_URL || 'http://localhost:3000');
298313
frontendUrl.searchParams.set('access_token', tokens.accessToken);
299314
frontendUrl.searchParams.set('refresh_token', tokens.refreshToken);
315+
frontendUrl.searchParams.set('returnUrl', finalReturnUrl);
300316

301317
this.log(
302318
'success',
@@ -305,6 +321,8 @@ export default class SamlController {
305321
'| Workspace:',
306322
sgr(workspaceId, Effect.ForegroundCyan),
307323
'| Redirecting to:',
324+
sgr(callbackPath, Effect.ForegroundGray),
325+
'→',
308326
sgr(finalReturnUrl, Effect.ForegroundGray)
309327
);
310328

0 commit comments

Comments
 (0)