Feat/MCP Authentication + alignment with REST and SKILL adapters #309
Open
Feat/MCP Authentication + alignment with REST and SKILL adapters #309
Conversation
eskenazit
requested changes
Apr 13, 2026
src/main/java/io/naftiko/engine/exposes/OAuth2AuthenticationRestlet.java
Outdated
Show resolved
Hide resolved
src/main/java/io/naftiko/engine/exposes/OAuth2AuthenticationRestlet.java
Show resolved
Hide resolved
src/main/java/io/naftiko/engine/exposes/OAuth2AuthenticationRestlet.java
Show resolved
Hide resolved
22e64b2 to
9fdee47
Compare
813adaa to
80f17bd
Compare
Contributor
Author
|
@eskenazit Excellent review. I was able to fix all issues, adding related test cases. |
19b4b9f to
19305a5
Compare
9fdee47 to
ba484fe
Compare
Contributor
|
I just realised that this branch is not from I think this is why there are conflicts, since the rebase of |
19305a5 to
ec6ed90
Compare
Contributor
Author
|
@eskenazit Yes this was intentional for the branch, but I should have been explicit. I just rebased on main (now that the Restlet transport PR has been merged), which was straightforward (no conflict to resolve) |
ec6ed90 to
c15a474
Compare
eskenazit
requested changes
Apr 14, 2026
src/main/java/io/naftiko/engine/exposes/OAuth2AuthenticationRestlet.java
Outdated
Show resolved
Hide resolved
…r chain - Add AuthOAuth2 to the shared Authentication union in the JSON schema - Add OAuth2AuthenticationSpec for YAML deserialization - Create OAuth2AuthenticationRestlet with JWKS-based JWT validation, AS metadata discovery, and token caching - Create McpOAuth2Restlet extending the shared restlet with MCP Protected Resource Metadata (RFC 9728) - Lift authentication field and buildServerChain into ServerAdapter base class, eliminating duplication across MCP, REST, and Skill - MCP adapter overrides createOAuth2Restlet for McpOAuth2Restlet - Add nimbus-jose-jwt 9.37.3 dependency for JWT/JWKS handling - Add 3 Spectral rules for OAuth2 validation - Add ServerAdapterAuthenticationTest (9 tests) for shared auth chain - Add OAuth2AuthenticationRestletTest (18 tests) for JWT validation - Add McpOAuth2RestletTest (8 tests) for MCP metadata extension - Add McpOAuth2IntegrationTest (5 tests) with mock AS server
… use Restlet HTTP client
validateClaims checked exp but not nbf — a JWT with nbf in the future was accepted. Added nbf check and corresponding unit tests.
c15a474 to
4302ff1
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.
Related Issue
Closes #294
What does this PR do?
Adds OAuth 2.1 resource server authentication to Naftiko, shared across all three server adapters (REST, MCP, Skill). This is a follow-up to #308 (Restlet transport migration) and builds on the unified Restlet foundation.
Key changes:
AuthOAuth2— new authentication type in the JSON schema (type: oauth2) with properties:authorizationServerUrl,resource,scopes,audience,tokenValidationOAuth2AuthenticationSpec— Java spec class registered in theAuthenticationSpec@JsonSubTypesunionOAuth2AuthenticationRestlet— shared JWT/JWKS validation restlet with AS metadata discovery (RFC 8414), JWKS caching,ChallengeRequest-basedWWW-AuthenticateMcpOAuth2Restlet— extendsOAuth2AuthenticationRestletwith MCP Protected Resource Metadata endpoint (RFC 9728)ServerAdapter— factored all authentication chain logic (buildServerChain,createOAuth2Restlet,buildChallengeAuthenticator, template/constant helpers) into the base class; MCP overridescreateOAuth2Restlet→McpOAuth2RestletServerSpec— liftedauthenticationfield fromMcpServerSpec,RestServerSpec,SkillServerSpecinto the base classnaftiko-oauth2-https-authserver(error),naftiko-oauth2-resource-https(warn),naftiko-oauth2-scopes-defined(warn)nimbus-jose-jwt9.37.3 — new dependency for JWT parsing and JWKS key resolutionmcp-server-authentication.mdto reflect Restlet foundationFactorization: Three rounds of factorization eliminated ~250+ lines of duplicated auth logic across the three adapters.
buildServerChain(Restlet)reads authentication fromgetSpec().getAuthentication()internally, so adapters just callbuildServerChain(router)with no wrapper methods.Tests
OAuth2AuthenticationRestletTest— 18 unit tests for JWT validation (missing token, expired, wrong issuer, wrong audience, wrong scope, JWKS key resolution, etc.)McpOAuth2RestletTest— 8 unit tests for MCP Protected Resource Metadata endpointMcpOAuth2IntegrationTest— 5 integration tests with mock authorization serverMcpAuthenticationIntegrationTest— 4 integration tests for basic/bearer/apikey/digest on MCPServerAdapterAuthenticationTest— 9 centralized tests for the shared authentication chain across all adapter typesChecklist
mainAgent Context (optional)