Skip to content

Feature/keep session alive oauth - #5071

Open
xb058t wants to merge 4 commits into
Ericsson:masterfrom
xb058t:feature/keep-session-alive-oauth-v2
Open

xb058t wants to merge 4 commits into
Ericsson:masterfrom
xb058t:feature/keep-session-alive-oauth-v2

Conversation

@xb058t

@xb058t xb058t commented Sep 3, 2026

Copy link
Copy Markdown
Collaborator

Closes #5047

Extends an OAuth session silently whenever session_lifetime lapses.
While the access token received at login is still valid, the session
is extended locally. Once it expires, a new access token is requested
with the stored refresh token, and the user is only sent back to the
login page if the provider refuses it.

Adds oauth_tokens.provider (model and migration) so the server knows
which provider to contact, and exempts OAuth backed sessions from the
unconditional expired session cleanup, which would otherwise delete
their refresh token on server startup or on another login.
Extends the OAuth login test to also check the persisted provider
value, not just access_token.
Teaches the mock provider's /token endpoint to honor a
grant_type=refresh_token request by issuing a new, distinct access
token and rejecting unknown refresh tokens.
@xb058t
xb058t requested a review from bruntib as a code owner September 3, 2026 10:02
@xb058t
xb058t requested a review from Discookie September 3, 2026 10:02
@xb058t xb058t added database 🗄️ Issues related to the database schema. test ☑️ Adding or refactoring tests new feature 👍 New feature request labels Sep 3, 2026
"expires at %s.", token[:8], oauth_token.expires_at)
return True
except Exception as e:
LOG.warning("OAuth session extension failed for %s...: %s",

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.

Does an expired refresh_token throw an exception via authlib?
If it does, then that needs to be handled explicitly, because it's not a warning-level issue.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes, OAuthError. Handled it separately at info level, other errors are logged at error level now. Added unit tests.

Comment on lines +1207 to +1209
if new_token.get('expires_in') is not None:
oauth_token.expires_at = \
now + timedelta(seconds=new_token['expires_in'])

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.

authlib constructs an expires_at value on its own inside new_token, even if the server does not return that value.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Changed to authlib's expires_at.

return local_session

if self.__try_extend_oauth_session(token):
local_session.last_access = datetime.now()

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.

This does not update the database, does it? Use local_session.revalidate(), or do the full revalidation inside try_extend_oauth_session.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

DB was updated in __try_extend_oauth_session, but revalidate() skips expired sessions. Moved the in-memory update there too.

oauth_config['token_url'],
refresh_token=oauth_token.refresh_token)

if not new_token.get('access_token'):

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.

Have you tested that there's a non-Exception code path here that does not contain an access_token? I feel like both this and checking for expires_in is needlessly paranoid.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Not tested, you're right. Removed both checks.

@xb058t
xb058t force-pushed the feature/keep-session-alive-oauth-v2 branch 2 times, most recently from 8334e5f to 1e859bb Compare October 8, 2026 22:22
@xb058t
xb058t force-pushed the feature/keep-session-alive-oauth-v2 branch from 1e859bb to 1a37f76 Compare October 8, 2026 22:34
@xb058t
xb058t requested a review from Discookie October 8, 2026 23:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

database 🗄️ Issues related to the database schema. new feature 👍 New feature request test ☑️ Adding or refactoring tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Keep CodeChecker GUI session alive until OAuth session is active

3 participants