fix: set IUserSession user after bearer token validation#1376
Open
hangerrits wants to merge 2 commits intonextcloud:mainfrom
Open
fix: set IUserSession user after bearer token validation#1376hangerrits wants to merge 2 commits intonextcloud:mainfrom
hangerrits wants to merge 2 commits intonextcloud:mainfrom
Conversation
6e362a4 to
14378e9
Compare
solracsf
reviewed
Mar 13, 2026
solracsf
approved these changes
Mar 14, 2026
julien-nc
requested changes
Mar 16, 2026
Member
julien-nc
left a comment
There was a problem hiding this comment.
LGTM. Thanks.
If you can rebase on main and fix the cs issue (run composer run cs:fix), let's merge that soon.
Signed-off-by: Han Gerrits <han@gerrits.net> fix: set IUserSession user after bearer token validation" --body "## Summary When user_oidc validates a bearer token in Backend::getCurrentUserId(), it returns the correct userId but does not call IUserSession::setUser(). This leaves the user session in an inconsistent state where getCurrentUserId() succeeds but DI-injected \$userId parameters remain null. ## Problem OCS controllers and CalDAV plugins that receive \$userId via dependency injection get null instead of the authenticated user's ID when the request is authenticated via OIDC bearer token. This causes: - **Deck**: TypeError: ...\$userId must be of type string, null given - **Talk**: Same TypeError pattern - **Tasks** (CalDAV): 500 errors from null userId These apps work correctly with session-based OIDC login (where setUser() IS called) but fail with bearer token authentication. ## Fix Call IUserSession::setUser() after successful bearer token validation at all three return points in getCurrentUserId(). IUserSession is resolved via Server::get() rather than constructor injection to avoid a circular dependency. ## Testing 1. Configure an OIDC provider with bearer token validation enabled 2. Make API requests to Deck, Talk, or CalDAV endpoints using a bearer token 3. Verify 200 responses instead of 500 errors"
agree, that's better Co-authored-by: Git'Fellow <12234510+solracsf@users.noreply.github.com> Signed-off-by: Han Gerrits <han@newtech.studio>
14a2c8e to
7f8893e
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
When user_oidc validates a bearer token in Backend::getCurrentUserId(), it returns the correct userId but does not call IUserSession::setUser().
This leaves the user session in an inconsistent state where getCurrentUserId() succeeds but DI-injected $userId parameters remain null.
Problem
OCS controllers and CalDAV plugins that receive $userId via dependency injection get null instead of the authenticated user's ID when the request
is authenticated via OIDC bearer token. This causes:
These apps work correctly with session-based OIDC login (where setUser() IS called) but fail with bearer token authentication.
Fix
Call IUserSession::setUser() after successful bearer token validation at all three return points in getCurrentUserId(). IUserSession is resolved via
Server::get() rather than constructor injection to avoid a circular dependency.
Testing