Skip to content

feat(core): expose oidc session uid on ctx.auth#8728

Open
simeng-li wants to merge 1 commit intomasterfrom
simeng-log-13303-p11-plumb-sessionuid-through-koaoidcauth-into-ctxauth
Open

feat(core): expose oidc session uid on ctx.auth#8728
simeng-li wants to merge 1 commit intomasterfrom
simeng-log-13303-p11-plumb-sessionuid-through-koaoidcauth-into-ctxauth

Conversation

@simeng-li
Copy link
Copy Markdown
Contributor

@simeng-li simeng-li commented Apr 28, 2026

Summary

Plumb the access token's sessionUid (already persisted on every session-backed AccessToken model by node-oidc-provider) through koaOidcAuth so route handlers can identify the current OIDC session. Adds an optional sessionUid?: string to the user Auth type and forwards the value verbatim from the verified access token.

This is groundwork for the upcoming isCurrent flag on the GET /api/my-account/sessions response — see GitHub #8681. No consumer reads ctx.auth.sessionUid yet; that lands in the next PR (P1.2).

Testing

Unit tests

Checklist

  • .changeset
  • unit tests
  • integration tests
  • necessary TSDoc comments

@github-actions github-actions Bot added the feature Cool stuff label Apr 28, 2026
@github-actions
Copy link
Copy Markdown

COMPARE TO master

Total Size Diff 📈 +874 Bytes

Diff by File
Name Diff
packages/core/src/middleware/koa-auth/koa-oidc-auth.test.ts 📈 +638 Bytes
packages/core/src/middleware/koa-auth/koa-oidc-auth.ts 📈 +30 Bytes
packages/core/src/middleware/koa-auth/types.ts 📈 +206 Bytes

@github-actions github-actions Bot removed the size/s label Apr 28, 2026
@simeng-li simeng-li requested review from a team April 28, 2026 02:40
@darcyYe
Copy link
Copy Markdown
Contributor

darcyYe commented Apr 28, 2026

Non-blocking suggestion: the runtime change only sets sessionUid from koaOidcAuth, which matches the P1.1 scope. The type is still a single broad Auth shape though (type: 'user' | 'app'), so sessionUid?: string is now also available at the type level for type: 'app' contexts.

The design note says not to add this to the M2M/app context. If we want the type contract to reflect that more strictly, we could split Auth into a discriminated union, e.g. UserAuth with optional sessionUid / clientId / identityVerified, and AppAuth without sessionUid. Current runtime behavior looks safe, so I’d treat this as a follow-up/nit rather than a blocker.

Copy link
Copy Markdown
Contributor

@wangsijie wangsijie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 PR Review

This PR plumbs the OIDC access token's session UID through koaOidcAuth into ctx.auth and adds focused unit coverage for both present and absent values.

  • 🔒 Security: clean
  • 🏗️ Architecture: clean
  • 👨‍💻 Engineering: clean

Verdict: ⚠️ Needs attention

@simeng-li
Copy link
Copy Markdown
Contributor Author

Non-blocking suggestion: the runtime change only sets sessionUid from koaOidcAuth, which matches the P1.1 scope. The type is still a single broad Auth shape though (type: 'user' | 'app'), so sessionUid?: string is now also available at the type level for type: 'app' contexts.

The design note says not to add this to the M2M/app context. If we want the type contract to reflect that more strictly, we could split Auth into a discriminated union, e.g. UserAuth with optional sessionUid / clientId / identityVerified, and AppAuth without sessionUid. Current runtime behavior looks safe, so I’d treat this as a follow-up/nit rather than a blocker.

AppAuth is not available for the user account API. So this is not an issue.

@simeng-li simeng-li force-pushed the simeng-log-13303-p11-plumb-sessionuid-through-koaoidcauth-into-ctxauth branch from 8306cbf to 10f30ed Compare April 28, 2026 05:57
@github-actions github-actions Bot added size/s and removed size/s labels Apr 28, 2026
Copy link
Copy Markdown
Contributor

@wangsijie wangsijie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 PR Review

This PR plumbs the OIDC access token's sessionUid onto ctx.auth as groundwork for upcoming session-aware APIs.

  • 🔒 Security: 0 high, 1 medium
  • 🏗️ Architecture: clean
  • 👨‍💻 Engineering: clean

Verdict: ⚠️ Needs attention

Comment on lines +11 to +15
/**
* OIDC session uid that backs the current access token, when the token was minted from an
* interactive (session-backed) flow. Absent for client-credentials tokens.
*/
sessionUid?: string;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔒 Medium: Adding sessionUid to the shared WithAuthContext lets handlers type-check against ctx.auth.sessionUid even on routes backed by other auth middlewares where that field is never populated at runtime.

Copy link
Copy Markdown
Contributor Author

@simeng-li simeng-li Apr 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keeping sessionUid?: string on the shared Auth type for now. The same shape already carries identityVerified?: boolean and clientId?: string, both of which are populated only by koa-oidc-auth and likewise typed-but-undefined for handlers behind other middlewares. Adding sessionUid follows the established pattern; tightening it (discriminated union over type: 'user' | 'app', or moving it to a separate context decoration) is a wider refactor that touches every ctx.auth consumer in the repo.

Plumb the access token's `sessionUid` (already persisted on every
session-backed AccessToken model) through `koaOidcAuth` so route
handlers protected by the middleware can identify the current OIDC
session. Adds an optional `sessionUid?: string` to the user `Auth`
type and forwards the value verbatim from the verified access token.

This is groundwork for `isCurrent` tagging on the Account API
sessions response (P1.2 / LOG-13304); no consumer reads the field
yet.

Refs LOG-13303
@simeng-li simeng-li force-pushed the simeng-log-13303-p11-plumb-sessionuid-through-koaoidcauth-into-ctxauth branch from 10f30ed to 52f33ba Compare April 29, 2026 07:52
@github-actions github-actions Bot added size/s and removed size/s labels Apr 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

3 participants