Skip to content

Refactor and isolate OAuth / OIDC helpers in enterprise/authentication#1148

Merged
jviotti merged 3 commits into
mainfrom
oidc-oauth
Jul 19, 2026
Merged

Refactor and isolate OAuth / OIDC helpers in enterprise/authentication#1148
jviotti merged 3 commits into
mainfrom
oidc-oauth

Conversation

@jviotti

@jviotti jviotti commented Jul 18, 2026

Copy link
Copy Markdown
Member

Signed-off-by: Juan Cruz Viotti jv@jviotti.com

Review in cubic

Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
@jviotti
jviotti marked this pull request as ready for review July 18, 2026 22:49
@augmentcode

augmentcode Bot commented Jul 18, 2026

Copy link
Copy Markdown
🤖 Augment PR Summary

Summary: This PR refactors the enterprise OAuth/OIDC implementation by extracting the protocol helpers into isolated, header-only modules under enterprise/authentication.

Changes:

  • Introduces authentication_oauth.h (state/PKCE + URL/body composition) and authentication_oidc.h (discovery parsing + ID token parsing/validation).
  • Updates enterprise authentication runtime to use oidc_discovery_url and oidc_parse_provider_metadata when resolving JWKS metadata.
  • Updates enterprise server login/callback handlers to use the new OAuth/OIDC primitives (state/nonce/verifier, token exchange, ID token parsing, validation).
  • Removes the prior compiled helper implementations (enterprise/authentication/discovery.cc, enterprise/authentication/oidc.cc) and the corresponding public headers from the shared include tree.
  • Adjusts build configuration to treat OAuth/OIDC helpers as enterprise-only header includes.
  • Removes enterprise unit tests covering discovery/OIDC helpers.

🤖 Was this summary useful? React with 👍 or 👎

@augmentcode augmentcode Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review completed. 3 suggestions posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

Comment thread src/authentication/CMakeLists.txt Outdated
target_compile_definitions(sourcemeta_one_authentication PUBLIC SOURCEMETA_ONE_ENTERPRISE)
# The OAuth and OIDC modules are header-only and enterprise-only, kept apart
# from the shared include tree so they extract cleanly when upstreamed
target_include_directories(sourcemeta_one_authentication PUBLIC

@augmentcode augmentcode Bot Jul 18, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

sourcemeta_one_authentication now exposes enterprise/authentication as a PUBLIC include dir (OAuth/OIDC are header-only), but the libraries those headers call into (sourcemeta::core::crypto, sourcemeta::core::uri, etc.) are still linked PRIVATE. This can cause downstream targets that include these headers (e.g., the enterprise server actions) to hit unresolved symbols unless they also link those deps explicitly.

Severity: medium

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

sourcemeta_test(NAMESPACE sourcemeta PROJECT one NAME enterprise_authentication
SOURCES authentication_test.cc session_test.cc discovery_test.cc
oidc_test.cc)
SOURCES authentication_test.cc session_test.cc)

@augmentcode augmentcode Bot Jul 18, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This drops discovery_test.cc/oidc_test.cc from the enterprise auth unit target, which removes coverage for the refactored discovery parsing, PKCE challenge derivation, and ID-token parsing/validation helpers. Since these helpers are still security-critical behavior (even though now header-only), it seems worth ensuring equivalent unit coverage still exists.

Severity: medium

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

#endif

#include <sourcemeta/one/authentication_discovery.h>
#include <sourcemeta/one/authentication_error.h>

@augmentcode augmentcode Bot Jul 18, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

sourcemeta/one/authentication.h no longer includes the discovery/OIDC helper headers (and those public headers are removed), which is a breaking change for any downstream code that previously relied on those symbols via this umbrella include. If this API reduction is intentional, consider ensuring release/upgrade notes (or an enterprise-only replacement include path) cover the change so consumers don’t silently lose those interfaces.

Severity: low

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

3 issues found across 16 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/authentication/CMakeLists.txt">

<violation number="1" location="src/authentication/CMakeLists.txt:11">
P1: The `enterprise/authentication` include directory is exposed as `PUBLIC`, making the header-only OAuth/OIDC helpers available to downstream targets. However, the libraries those inline functions call into (`sourcemeta::core::crypto`, `sourcemeta::core::uri`, `sourcemeta::core::jose` via the OIDC header) are still linked `PRIVATE`. Downstream consumers that include these headers and instantiate the inline functions in their own translation units will hit unresolved symbols at link time unless they independently link those deps. Either promote `crypto`, `uri`, and `jose` to `PUBLIC` here, or keep them `PRIVATE` and make the include directory `PRIVATE` as well (requiring downstream targets to add the include path themselves alongside explicit link deps).</violation>
</file>

<file name="enterprise/unit/authentication/CMakeLists.txt">

<violation number="1" location="enterprise/unit/authentication/CMakeLists.txt:2">
P2: Removing `discovery_test.cc` and `oidc_test.cc` from the enterprise unit target drops ~450 lines of tests covering security-critical behavior: PKCE challenge derivation (pinned against RFC 7636 Appendix B), ID-token signature verification, nonce binding, audience restriction, and subject validation. Since the logic is unchanged (just moved to header-only), equivalent unit coverage should still exist. If these tests have been relocated to a different target, this is fine—but I don't see replacement tests in the changeset.</violation>
</file>

<file name="enterprise/authentication/authentication_oidc.h">

<violation number="1" location="enterprise/authentication/authentication_oidc.h:80">
P1: OIDC discovery responses with a mismatched `issuer` are accepted because this metadata parser drops the required issuer field. That violates Discovery provider-configuration validation and lets an otherwise valid JSON response redirect authorization, token, and JWKS operations to endpoints belonging to a different issuer; retaining and checking the returned issuer against the configured value would keep discovery bound to the configured provider.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread src/authentication/CMakeLists.txt Outdated
Comment thread enterprise/authentication/authentication_oidc.h
sourcemeta_test(NAMESPACE sourcemeta PROJECT one NAME enterprise_authentication
SOURCES authentication_test.cc session_test.cc discovery_test.cc
oidc_test.cc)
SOURCES authentication_test.cc session_test.cc)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2: Removing discovery_test.cc and oidc_test.cc from the enterprise unit target drops ~450 lines of tests covering security-critical behavior: PKCE challenge derivation (pinned against RFC 7636 Appendix B), ID-token signature verification, nonce binding, audience restriction, and subject validation. Since the logic is unchanged (just moved to header-only), equivalent unit coverage should still exist. If these tests have been relocated to a different target, this is fine—but I don't see replacement tests in the changeset.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At enterprise/unit/authentication/CMakeLists.txt, line 2:

<comment>Removing `discovery_test.cc` and `oidc_test.cc` from the enterprise unit target drops ~450 lines of tests covering security-critical behavior: PKCE challenge derivation (pinned against RFC 7636 Appendix B), ID-token signature verification, nonce binding, audience restriction, and subject validation. Since the logic is unchanged (just moved to header-only), equivalent unit coverage should still exist. If these tests have been relocated to a different target, this is fine—but I don't see replacement tests in the changeset.</comment>

<file context>
@@ -1,6 +1,5 @@
 sourcemeta_test(NAMESPACE sourcemeta PROJECT one NAME enterprise_authentication
-  SOURCES authentication_test.cc session_test.cc discovery_test.cc
-    oidc_test.cc)
+  SOURCES authentication_test.cc session_test.cc)
 
 target_link_libraries(sourcemeta_one_enterprise_authentication_unit
</file context>
Suggested change
SOURCES authentication_test.cc session_test.cc)
SOURCES authentication_test.cc session_test.cc discovery_test.cc
oidc_test.cc)

@github-actions github-actions Bot left a comment

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.

Benchmark Index (community)

Details
Benchmark suite Current: a257b66 Previous: 43e17de Ratio
Add one schema (0 existing) 333 ms 327 ms 1.02
Add one schema (100 existing) 28 ms 30 ms 0.93
Add one schema (1000 existing) 85 ms 87 ms 0.98
Add one schema (10000 existing) 708 ms 783 ms 0.90
Update one schema (1 existing) 21 ms 22 ms 0.95
Update one schema (101 existing) 29 ms 30 ms 0.97
Update one schema (1001 existing) 87 ms 89 ms 0.98
Update one schema (10001 existing) 701 ms 817 ms 0.86
Cached rebuild (1 existing) 7 ms 7 ms 1
Cached rebuild (101 existing) 9 ms 9 ms 1
Cached rebuild (1001 existing) 29 ms 30 ms 0.97
Cached rebuild (10001 existing) 244 ms 267 ms 0.91
Index 100 schemas 492 ms 441 ms 1.12
Index 1000 schemas 1486 ms 1467 ms 1.01
Index 10000 schemas 13521 ms 14032 ms 0.96
Index 10000 schemas (custom meta-schema) 16443 ms 17074 ms 0.96
Index 10000 schemas ($ref fan-out) 16351 ms 16623 ms 0.98

This comment was automatically generated by workflow using github-action-benchmark.

@github-actions github-actions Bot left a comment

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.

Benchmark Index (enterprise)

Details
Benchmark suite Current: a257b66 Previous: 43e17de Ratio
Add one schema (0 existing) 396 ms 400 ms 0.99
Add one schema (100 existing) 105 ms 104 ms 1.01
Add one schema (1000 existing) 159 ms 157 ms 1.01
Add one schema (10000 existing) 798 ms 759 ms 1.05
Update one schema (1 existing) 97 ms 96 ms 1.01
Update one schema (101 existing) 102 ms 102 ms 1
Update one schema (1001 existing) 160 ms 156 ms 1.03
Update one schema (10001 existing) 765 ms 767 ms 1.00
Cached rebuild (1 existing) 8 ms 8 ms 1
Cached rebuild (101 existing) 10 ms 10 ms 1
Cached rebuild (1001 existing) 31 ms 30 ms 1.03
Cached rebuild (10001 existing) 252 ms 250 ms 1.01
Index 100 schemas 749 ms 497 ms 1.51
Index 1000 schemas 1579 ms 1525 ms 1.04
Index 10000 schemas 13945 ms 13610 ms 1.02
Index 10000 schemas (custom meta-schema) 17195 ms 16533 ms 1.04
Index 10000 schemas ($ref fan-out) 17023 ms 16426 ms 1.04

This comment was automatically generated by workflow using github-action-benchmark.

jviotti added 2 commits July 18, 2026 20:51
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
@jviotti
jviotti merged commit 311eb19 into main Jul 19, 2026
5 checks passed
@jviotti
jviotti deleted the oidc-oauth branch July 19, 2026 00:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant