Skip to content

Commit bbd6a5f

Browse files
committed
feat: Enhance authentication response to include session type, unifying output across standalone, OIDC, and TrueFoundry modes
1 parent c2dde14 commit bbd6a5f

5 files changed

Lines changed: 16 additions & 2 deletions

File tree

‎.changeset/unified-request-context-auth.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
'@truefoundry/trueforge': minor
33
---
44

5-
Unify request-scoped RequestContext across standalone, OIDC, and TrueFoundry auth. `/auth/me` returns `{ data: { tenant_id, subject, roles } }` (OpenAPI/SDK regen deferred to CI).
5+
Unify request-scoped RequestContext across standalone, OIDC, and TrueFoundry auth. `/auth/me` returns `{ data: { type, tenant_id, subject, roles } }` (`type` is `oidc-connected` | `default`; OpenAPI/SDK regen deferred to CI).

‎packages/trueforge/src/apis/auth.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ export function createAuthRouter(params: {
124124
const requestContext = resolveRequestContext(c);
125125
const body: GetMeResponse = {
126126
data: {
127+
// FE logout chrome keys off `oidc-connected` (browser SSO cookie session).
128+
type: params.oidcClient !== undefined ? 'oidc-connected' : 'default',
127129
tenant_id: requestContext.tenant_id,
128130
subject: requestContext.subject,
129131
roles: requestContext.roles,

‎packages/trueforge/src/routes/authRoutes.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ export const meRoute = createRoute({
6363
tags: [OpenApiTag.AUTH],
6464
summary: 'Current session',
6565
description:
66-
'Returns the authenticated caller identity (`tenant_id`, `subject`, `roles`) wrapped as `{ data }`. When auth is enabled ' +
66+
'Returns the authenticated caller identity (`type`, `tenant_id`, `subject`, `roles`) wrapped as `{ data }`. ' +
67+
'`type` is `oidc-connected` when browser OIDC is enabled, otherwise `default`. When auth is enabled ' +
6768
'this requires a valid `id_token` cookie or `Authorization: Bearer` token (401 otherwise). When auth is ' +
6869
'disabled, returns the standalone default identity.',
6970
'x-fern-sdk-group-name': ['auth'],

‎packages/trueforge/src/schemas/auth.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,16 @@ export const GetMeSubjectSchema = z
3636
})
3737
.openapi('GetMeSubject');
3838

39+
export const MeSessionTypeSchema = z
40+
.enum(['default', 'oidc-connected'])
41+
.describe(
42+
'`oidc-connected` when the process is running with browser OIDC login; `default` for standalone or TrueFoundry token auth.',
43+
)
44+
.openapi('MeSessionType');
45+
3946
export const MeSchema = z
4047
.object({
48+
type: MeSessionTypeSchema,
4149
tenant_id: z.string().describe('Tenant scope for the authenticated caller.'),
4250
subject: GetMeSubjectSchema,
4351
roles: z.array(z.string()).describe('Roles for the authenticated caller.'),
@@ -47,5 +55,6 @@ export const MeSchema = z
4755
export const GetMeResponseSchema = z.object({ data: MeSchema }).openapi('GetMeResponse');
4856

4957
export type GetMeSubject = z.infer<typeof GetMeSubjectSchema>;
58+
export type MeSessionType = z.infer<typeof MeSessionTypeSchema>;
5059
export type Me = z.infer<typeof MeSchema>;
5160
export type GetMeResponse = z.infer<typeof GetMeResponseSchema>;

‎packages/trueforge/tests/unit/apis/auth.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ describe('auth router (no identity provider configured)', () => {
105105
expect(res.status).toBe(200);
106106
expect(await res.json()).toEqual({
107107
data: {
108+
type: 'default',
108109
tenant_id: STANDALONE_REQUEST_CONTEXT.tenant_id,
109110
subject: STANDALONE_REQUEST_CONTEXT.subject,
110111
roles: STANDALONE_REQUEST_CONTEXT.roles,
@@ -480,6 +481,7 @@ describe('auth router (auth enabled)', () => {
480481
expect(res.status).toBe(200);
481482
expect(await res.json()).toEqual({
482483
data: {
484+
type: 'oidc-connected',
483485
tenant_id: 'default',
484486
subject: { id: 'user-1', type: 'user', display_name: 'user-1' },
485487
roles: [],

0 commit comments

Comments
 (0)