Skip to content

Refactor handling of OAuth client tokens - #24684

Closed
NobodysNightmare wants to merge 5 commits into
devfrom
oauth-client-tokens
Closed

Refactor handling of OAuth client tokens#24684
NobodysNightmare wants to merge 5 commits into
devfrom
oauth-client-tokens

Conversation

@NobodysNightmare

@NobodysNightmare NobodysNightmare commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Previously the fetching and updating of OAuthClientToken was left as an implementation detail of specific integrations, even though the concept of OAuthClient and OAuthClientToken were defined in the core and even their creation is already handled through a core class (the ConnectionManager).

This PR introduces the OAuthClients::TokenFetcher that serves as the new main interface to obtain the access token of an OAuthClientToken. A relevant difference compared to the previous approach is that we refresh access tokens based on their time-to-live (i.e. expires_in), not based on receiving an error response and then retrying.

Ticket

https://community.openproject.org/wp/SI-236

@NobodysNightmare
NobodysNightmare marked this pull request as draft August 10, 2026 15:02
@NobodysNightmare
NobodysNightmare changed the base branch from dev to harmonize-errors August 11, 2026 08:40
@NobodysNightmare
NobodysNightmare force-pushed the oauth-client-tokens branch 2 times, most recently from ea33ca1 to 2b730ff Compare August 11, 2026 09:04
Base automatically changed from harmonize-errors to dev August 11, 2026 09:29
@NobodysNightmare
NobodysNightmare force-pushed the oauth-client-tokens branch 5 times, most recently from e35547d to 5664fc9 Compare August 12, 2026 06:19
@github-actions

Copy link
Copy Markdown

Warning

Flaky specs

  • rspec ./spec/features/workflows/edit_spec.rb[1:7:8]
🤖 Ask Copilot to investigate

Copy the prompt below into a new comment on this PR to delegate the investigation to GitHub Copilot. It will look into the flakiness and open a separate pull request with you as reviewer.

@copilot The following spec(s) are flaky in CI (first seen on PR #24684, linked for reference only):

- `rspec ./spec/features/workflows/edit_spec.rb[1:7:8]`

Treat this as a standalone task, unrelated to PR #24684. Create a new branch from origin/dev and open a new pull request targeting dev — do not stack it on PR #24684 or reuse that branch.

Follow the playbook in docs/development/testing/handling-flaky-tests/README.md to find the root cause and fix the underlying race — do not skip, delete, or weaken the spec to make it pass; disabling is a last resort per the playbook, and only with a bug ticket. Verify the fix by running the spec(s) repeatedly (e.g. `script/bulk_run_rspec --run-count 10`).

If you cannot reproduce the flake or are not confident in a fix after reasonable investigation, do not fabricate a change or skip the spec to force CI green. Instead, leave the pull request in draft and document what you tried, the suspected cause, and any leads in its description, then assign @NobodysNightmare to take over.

Once the fix is verified, title the PR after the spec(s) it fixes, and use the PR description to explain the root cause, how the change resolves it, and the before/after results. Label the PR `flaky-spec`, assign @NobodysNightmare, and request a review from @NobodysNightmare.
On every commit, set @NobodysNightmare as the sole co-author with a `Co-authored-by:` trailer (use their GitHub no-reply email so it links to their account), so it is traceable who dispatched the fix.

@github-actions

Copy link
Copy Markdown

Warning

Flaky specs

  • rspec ./modules/backlogs/spec/features/inbox_column_spec.rb[1:7:1]
  • rspec ./spec/features/work_packages/details/inplace_editor/version_editor_spec.rb[1:1:2]
🤖 Ask Copilot to investigate

Copy the prompt below into a new comment on this PR to delegate the investigation to GitHub Copilot. It will look into the flakiness and open a separate pull request with you as reviewer.

@copilot The following spec(s) are flaky in CI (first seen on PR #24684, linked for reference only):

- `rspec ./modules/backlogs/spec/features/inbox_column_spec.rb[1:7:1]`
- `rspec ./spec/features/work_packages/details/inplace_editor/version_editor_spec.rb[1:1:2]`

Treat this as a standalone task, unrelated to PR #24684. Create a new branch from origin/dev and open a new pull request targeting dev — do not stack it on PR #24684 or reuse that branch.

Follow the playbook in docs/development/testing/handling-flaky-tests/README.md to find the root cause and fix the underlying race — do not skip, delete, or weaken the spec to make it pass; disabling is a last resort per the playbook, and only with a bug ticket. Verify the fix by running the spec(s) repeatedly (e.g. `script/bulk_run_rspec --run-count 10`).

If you cannot reproduce the flake or are not confident in a fix after reasonable investigation, do not fabricate a change or skip the spec to force CI green. Instead, leave the pull request in draft and document what you tried, the suspected cause, and any leads in its description, then assign @NobodysNightmare to take over.

Once the fix is verified, title the PR after the spec(s) it fixes, and use the PR description to explain the root cause, how the change resolves it, and the before/after results. Label the PR `flaky-spec`, assign @NobodysNightmare, and request a review from @NobodysNightmare.
On every commit, set @NobodysNightmare as the sole co-author with a `Co-authored-by:` trailer (use their GitHub no-reply email so it links to their account), so it is traceable who dispatched the fix.

@NobodysNightmare
NobodysNightmare marked this pull request as ready for review August 12, 2026 07:36
@NobodysNightmare
NobodysNightmare requested a review from a team August 12, 2026 07:36
Comment thread app/services/oauth_clients/token_request.rb Outdated
@NobodysNightmare
NobodysNightmare force-pushed the oauth-client-tokens branch 3 times, most recently from a1e1290 to 92a355d Compare August 12, 2026 08:57
This class provides generic helpers to perform OAuth 2.0 token requests,
which are not only useful in the context of OpenID Connect, but also for other
kinds of OAuth clients.
Previously the fetching and updating of `OAuthClientToken` was left as an
implementation detail of specific integrations, even though the concept of
`OAuthClient` and `OAuthClientToken` were defined in the core and even their
creation is already handled through a core class (the `ConnectionManager`).

This commit introduces the `OAuthClients::TokenFetcher` that serves as
the new main interface to obtain the access token of an `OAuthClientToken`.
The previous cassette contained a refresh of an OAuth token that was performed
through the previous "try-and-error"-based approach for authentication.

I.e. the first request failed with an authentication error, then there was an additional
request included to refresh the OAuth token and the second request to the first endpoint
succeeded. This VCR cassette is incompatible with the new TTL-based authentication approach,
where a token is refreshed shortly before expiry, but not based on negative request outcomes.
Introducing a core class for logging that's inspired by the
Storages::TaggedLogging module. Though it aims to natively
support key-value-pairs during logging.

What still needs to be added is a way to temporarily add tags,
i.e. `with_log_tags { ... }`.
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 13, 2026
@NobodysNightmare

Copy link
Copy Markdown
Contributor Author

Follow me to #24726

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant