Repository navigation
fix(oauth2): revoke the tokens of a user when an admin locks the account #216
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
Open
romanetar
wants to merge
11
commits into
main
Choose a base branch
from
fix/revoke-tokens-on-user-lock
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+810
−10
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
7ca1b8e
fix(oauth2): revoke the tokens of a user when an admin locks the account
romanetar f816442
feat(admin): revoke all the tokens of a user from the edit user page
romanetar ac87518
style(admin): put the revoke all tokens button below the tokens grid,…
romanetar 267acf3
style(admin): match the revoke all tokens button to "Sign out all oth…
romanetar ea4cb90
fix(admin): refresh the access tokens grid with a functional state up…
romanetar bdc8ed6
fix(oauth2): stop issuing tokens to a locked user through a live sess…
romanetar 3c85ff5
fix(admin): revoke the tokens of a user deactivated from the edit use…
romanetar 370aa7b
refactor(admin): revoke all the tokens of a user through the service …
romanetar eec6415
fix(admin): do not let a user change its own active, email_verified o…
romanetar 42124ff
fix(auth): end the web session of a locked user on every authenticate…
romanetar d292042
fix(auth): do not count the session of a locked user as logged in on …
romanetar 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
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
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
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,43 @@ | ||
| <?php namespace App\Jobs; | ||
| /* | ||
| * Copyright 2026 OpenStack Foundation | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| **/ | ||
|
|
||
| use Auth\User; | ||
|
|
||
| /** | ||
| * Class RevokeUserGrantsOnAdminRequest | ||
| * Revokes all OAuth2 grants for a user across all clients when a server admin asks for it | ||
| * ("Revoke All Tokens" on the edit user page). | ||
| * @package App\Jobs | ||
| */ | ||
| class RevokeUserGrantsOnAdminRequest extends RevokeUserGrants | ||
| { | ||
| /** | ||
| * @param User $user the user whose grants are revoked | ||
| * @param User|null $admin the server admin who asked for it | ||
| */ | ||
| public function __construct(User $user, ?User $admin) | ||
| { | ||
| parent::__construct | ||
| ( | ||
| $user, | ||
| null, | ||
| sprintf | ||
| ( | ||
| "admin request by user %s (%s)", | ||
| !is_null($admin) ? $admin->getEmail() : 'N/A', | ||
| !is_null($admin) ? $admin->getId() : 'N/A' | ||
| ) | ||
| ); | ||
| } | ||
| } |
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,30 @@ | ||
| <?php namespace App\Jobs; | ||
| /* | ||
| * Copyright 2026 OpenStack Foundation | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| **/ | ||
|
|
||
| use Auth\User; | ||
|
|
||
| /** | ||
| * Class RevokeUserGrantsOnUserLocked | ||
| * Revokes all OAuth2 grants for a user across all clients after an administrative lock. | ||
| * @package App\Jobs | ||
| */ | ||
| class RevokeUserGrantsOnUserLocked extends RevokeUserGrants | ||
| { | ||
| const REASON = 'user locked'; | ||
|
|
||
| public function __construct(User $user) | ||
| { | ||
| parent::__construct($user, null, self::REASON); | ||
| } | ||
| } |
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
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
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use a persistent queue for lock-triggered revocation.
Laravel 12.73.0 executes
afterResponse()throughdispatchSync(). If revocation throws,SyncQueuefails the job without worker retries. The parent's$tries = 5does not provide recovery on this path. (raw.githubusercontent.com)If a database or cache operation fails after the lock succeeds, existing access tokens can remain usable with no pending retry. Dispatch to a persistent queue after commit so unfinished revocation can resume.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The mechanism is right:
afterResponse()runs the job throughdispatchSync, so ifrevokeUsersTokenthrows there is no worker retry andfailed()only logs. We are keeping it on purpose for this PR:RevokeUserGrantsOnPasswordChange,RevokeUserGrantsOnSessionRevocationandRevokeUserGrantsOnExplicitLogoutare dispatched withafterResponse()too. Moving only this one to a persistent queue would make the revoke jobs behave differently from each other. If we want retries, it should be a follow-up that changes all of them together.RevokeUserGrants::handlelogs the failed attempt andfailed()logs an error, and the admin can run "Revoke All Tokens" on the user's edit page (DELETE /admin/api/v1/users/{id}/tokens) as a manual fallback.On "after commit":
lockUser()dispatches once the transaction closure has returned, so the lock is already committed at that point.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@romanetar Thanks for explaining the trade-off. I understand the decision to keep
afterResponse()for this PR and consider retry changes across the revoke jobs together.I’m not marking the finding as addressed.
Learnings added
You are interacting with an AI system.