-
Notifications
You must be signed in to change notification settings - Fork 55
Make back-channel logout work on existing sessions #4767
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
crates/storage-pg/migrations/20250709142230_backfill_id_token_claims.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
-- Copyright 2025 New Vector Ltd. | ||
-- | ||
-- SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial | ||
-- Please see LICENSE in the repository root for full details. | ||
|
||
-- We may be running an older version of the app that doesn't fill in the | ||
-- id_token_claims column when the id_token column is populated. So we add a | ||
-- trigger to fill in the id_token_claims column if it's NULL. | ||
-- | ||
-- We will be able to remove this trigger in a future version of the app. | ||
-- | ||
-- We do this before the backfilling starts, to make sure we don't miss anything | ||
CREATE OR REPLACE FUNCTION fill_id_token_claims() | ||
RETURNS TRIGGER AS $$ | ||
BEGIN | ||
-- Only process if id_token_claims is NULL but id_token is not NULL | ||
IF NEW.id_token_claims IS NULL AND NEW.id_token IS NOT NULL AND NEW.id_token != '' THEN | ||
BEGIN | ||
-- Decode JWT payload inline | ||
NEW.id_token_claims := ( | ||
CASE | ||
WHEN split_part(NEW.id_token, '.', 2) = '' THEN NULL | ||
ELSE | ||
(convert_from( | ||
decode( | ||
replace(replace(split_part(NEW.id_token, '.', 2), '-', '+'), '_', '/') || | ||
repeat('=', (4 - length(split_part(NEW.id_token, '.', 2)) % 4) % 4), | ||
'base64' | ||
), | ||
'UTF8' | ||
))::JSONB | ||
END | ||
); | ||
EXCEPTION | ||
WHEN OTHERS THEN | ||
-- If JWT decoding fails, leave id_token_claims as NULL | ||
NEW.id_token_claims := NULL; | ||
END; | ||
END IF; | ||
|
||
RETURN NEW; | ||
END; | ||
$$ LANGUAGE plpgsql; | ||
|
||
-- Create the trigger | ||
CREATE TRIGGER trg_fill_id_token_claims | ||
BEFORE INSERT OR UPDATE ON upstream_oauth_authorization_sessions | ||
FOR EACH ROW | ||
sandhose marked this conversation as resolved.
Show resolved
Hide resolved
|
||
EXECUTE FUNCTION fill_id_token_claims(); | ||
|
||
-- This backfills the id_token_claims column in the upstream_oauth_authorization_sessions table | ||
-- by decoding the id_token column and storing the decoded claims in the id_token_claims column. | ||
UPDATE upstream_oauth_authorization_sessions | ||
SET id_token_claims = CASE | ||
WHEN id_token IS NULL OR id_token = '' THEN NULL | ||
WHEN split_part(id_token, '.', 2) = '' THEN NULL | ||
ELSE | ||
(convert_from( | ||
decode( | ||
replace(replace(split_part(id_token, '.', 2), '-', '+'), '_', '/') || | ||
repeat('=', (4 - length(split_part(id_token, '.', 2)) % 4) % 4), | ||
'base64' | ||
), | ||
'UTF8' | ||
))::JSONB | ||
END | ||
WHERE id_token IS NOT NULL AND id_token_claims IS NULL; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.