Skip to content

Add OIDC RP-Initiated Logout support to signOut()#36

Merged
madurangasiriwardena merged 1 commit into
thunder-id:mainfrom
madurangasiriwardena:rp-initiated-logout
Jul 22, 2026
Merged

Add OIDC RP-Initiated Logout support to signOut()#36
madurangasiriwardena merged 1 commit into
thunder-id:mainfrom
madurangasiriwardena:rp-initiated-logout

Conversation

@madurangasiriwardena

@madurangasiriwardena madurangasiriwardena commented Jul 22, 2026

Copy link
Copy Markdown
Member

Purpose

signOut() in the browser client previously only cleared the local session (a // TEMPORARY local sign out), leaving the OP's session intact. This PR implements OIDC RP-Initiated Logout so signOut() also terminates the session at the provider's end_session_endpoint, then returns the user to the app.

It is enabled by default and degrades gracefully: when the OP advertises no end_session_endpoint (or a sign-out URL cannot be built), it falls back to the existing local-only sign out, so consumers without an end-session endpoint are unaffected.


⚠️ Breaking Changes

🔧 Summary of Breaking Changes

  • signOut() now performs RP-Initiated Logout by default (redirecting to the end_session_endpoint) instead of only clearing the local session.
  • id_token_hint is now sent by default when an ID token is available (sendIdTokenInLogoutRequest default is effectively true), falling back to client_id otherwise.

💥 Impact

Consumers whose OP advertises an end_session_endpoint will now see signOut() redirect the browser to it (previously local-only). Consumers with no end_session_endpoint see no change.

🔄 Migration Guide

  • To keep the previous local-only behavior: set rpInitiatedLogout: false.
  • To always send client_id instead of id_token_hint: set sendIdTokenInLogoutRequest: false.

Approach

  • ThunderIDBrowserClient.signOut() resolves the sign-out URL (a cached URL built at token exchange, or freshly built for a targeted session) before clearing the local session, so the ID token used for id_token_hint is still available. It awaits the clear, then redirects to the end_session_endpoint. Gated by config.rpInitiatedLogout !== false (on by default) with a local-only fallback when no URL can be built.
  • ThunderIDJavaScriptClient.clearSessionAsync() (new, protected) is an awaitable variant of the fire-and-forget clearSession(), so the local clear completes before the full-page redirect. clearSession() is unchanged.
  • getSignOutUrl() now sets id_token_hint when an ID token is available and sendIdTokenInLogoutRequest is not false, otherwise client_id (no longer throws when the ID token is absent).
  • config.ts: rpInitiatedLogout (new) and sendIdTokenInLogoutRequest (existing) documented with @default true.

Related Issues

Related PRs

  • N/A

Checklist

  • Followed the contribution guidelines.
  • Manual test round performed and verified.
  • Documentation provided. (Add links if there are any)
  • Tests provided. (Add links if there are any)
    • Unit Tests
    • Integration Tests
  • Breaking changes. (Fill if applicable)
    • Breaking changes section filled.
    • breaking change label added.

Security checks

  • Followed secure coding standards in WSO2 Secure Coding Guidelines
  • Confirmed that this PR doesn't commit any keys, passwords, tokens, usernames, or other secrets.

Summary by CodeRabbit

  • New Features

    • Added OpenID Connect RP-initiated logout support, including browser redirection to the identity provider when configured.
    • Added an option to disable RP-initiated logout for local-only sign-out.
    • Improved logout URL generation with flexible id_token_hint and client_id handling.
    • Added support for targeting a specific session during sign-out.
  • Bug Fixes

    • Sign-out now falls back to local session clearing when a provider logout URL is unavailable or cannot be generated.
    • Session data is cleared before redirecting to the identity provider.

@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@madurangasiriwardena, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 8 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: f0695602-b1a9-4a53-89e1-62ce8f31a52e

📥 Commits

Reviewing files that changed from the base of the PR and between e2d884b and bd78aff.

📒 Files selected for processing (4)
  • packages/browser/src/ThunderIDBrowserClient.ts
  • packages/javascript/src/ThunderIDJavaScriptClient.ts
  • packages/javascript/src/__tests__/ThunderIDJavaScriptClient.test.ts
  • packages/javascript/src/models/config.ts
📝 Walkthrough

Walkthrough

OIDC RP-initiated logout is configurable, logout URL parameter selection is updated, and browser sign-out now clears sessions before navigating to the provider logout endpoint when available.

Changes

RP-initiated logout

Layer / File(s) Summary
Logout URL contract and construction
packages/javascript/src/models/config.ts, packages/javascript/src/ThunderIDJavaScriptClient.ts, packages/javascript/src/__tests__/ThunderIDJavaScriptClient.test.ts
Adds rpInitiatedLogout, updates sendIdTokenInLogoutRequest behavior, and tests end-session URL parameters and fallback cases.
Session clearing and browser navigation
packages/javascript/src/ThunderIDJavaScriptClient.ts, packages/browser/src/ThunderIDBrowserClient.ts
Adds awaitable session clearing and uses it before OP navigation, with local-only sign-out fallback when URL construction fails.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant BrowserClient
  participant JavaScriptClient
  participant AuthHelper
  participant OP
  BrowserClient->>JavaScriptClient: Build sign-out URL
  BrowserClient->>AuthHelper: Clear session asynchronously
  BrowserClient->>OP: Navigate to end-session URL
Loading

Suggested reviewers: brionmario

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: adding OIDC RP-Initiated Logout support to signOut().
Description check ✅ Passed The description follows the template well, covering Purpose, Approach, Breaking Changes, Related Issues/PRs, Checklist, and Security checks.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/browser/src/ThunderIDBrowserClient.ts`:
- Around line 392-416: Update the RP-initiated logout success branch in the
sign-out method so the optional afterSignOut callback is invoked after
clearSessionAsync and before navigating or returning. Preserve the existing
callback behavior in the local-only fallback and ensure the callback receives
the same session/logout context expected by callers.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 261b3f58-261e-4f5d-bd31-714c22098cc9

📥 Commits

Reviewing files that changed from the base of the PR and between 5fb410f and e2d884b.

📒 Files selected for processing (4)
  • packages/browser/src/ThunderIDBrowserClient.ts
  • packages/javascript/src/ThunderIDJavaScriptClient.ts
  • packages/javascript/src/__tests__/ThunderIDJavaScriptClient.test.ts
  • packages/javascript/src/models/config.ts

Comment thread packages/browser/src/ThunderIDBrowserClient.ts
signOut() performs OIDC RP-Initiated Logout by default: it resolves the sign-out
URL (post_logout_redirect_uri, plus id_token_hint when an ID token is available,
else client_id) before clearing the local session, then redirects to the OP's
end_session_endpoint. It falls back to a local-only sign out when no
end_session_endpoint is advertised or the URL cannot be built. Set
rpInitiatedLogout: false to force a local-only sign out, or
sendIdTokenInLogoutRequest: false to always send client_id.

Add clearSessionAsync so the local clear can complete before the redirect.
@madurangasiriwardena

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@madurangasiriwardena
madurangasiriwardena merged commit 7f165a2 into thunder-id:main Jul 22, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants