Skip to content

feat: add agw impl [EXPERIMENTAL] - #42

Draft
Schmarvinius wants to merge 3 commits into
mainfrom
feat/agw
Draft

feat: add agw impl [EXPERIMENTAL]#42
Schmarvinius wants to merge 3 commits into
mainfrom
feat/agw

Conversation

@Schmarvinius

@Schmarvinius Schmarvinius commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

feat: Add SAP Agent Gateway Adapter with IAS JWT-Bearer Token Exchange

This PR introduces a new n8n-to-gateway adapter that routes n8n workflow invocations through the SAP Agent Gateway, implementing the first authentication gate: IAS JWT-bearer token exchange via mTLS.

🆕 New Files

lib/auth/agent-gateway-credentials.js
Resolves Agent Gateway credentials from cds.requires.n8n.credentials.agentGateway. Supports flexible configuration via:

  • Inline values
  • File references (certificateFile, privateKeyFile) for local development
  • A single crdFile JSON (consumed resource definition)

Validates required fields (clientid, iasUrl, certificate, key) and normalizes the IAS URL to its origin for @sap/xssec discovery.

lib/auth/token-exchange.js
Performs the IAS JWT-bearer assertion ("Exchange Access Token") using @sap/xssec's IdentityService. Exchanges the authenticated user's JWT for a token scoped to the Agent Gateway via urn:sap:identity:application:provider:name:agent-gateway. Includes a lazily-initialized, keyed cache for the IdentityService instance and exposes test hooks (_resetCache, _setIdentityServiceFactory).

srv/n8n-to-gateway.js + srv/n8n-to-gateway.cds
The new gateway adapter extending N8nRestService. Implements Gate 1 (IAS assertion) fully. Gate 2+ (actual Agent Gateway invocation via MCP endpoint) is stubbed with a TODO and a warning log.

🔧 Modified Files

lib/handlers/triggerHandler.js

  • Switches from n8n.trigger(...) to n8n.send({ event: 'trigger', ... }) to support outbox-persisted headers.
  • Captures the user's JWT synchronously in the originating request context and forwards it via x-agw-user-assertion header for async delivery.

package.json

  • Adds @sap/xssec: ^4 as a runtime dependency.
  • Registers the new n8n-to-gateway kind in the CDS plugin configuration.

Change Type

🆕 New Feature

Have you...

  • Added relevant entry to the change log?

  • 🔄 Regenerate and Update Summary

PR Bot Information

Version: 1.29.54

  • LLM: anthropic--claude-4.6-sonnet
  • Summary Prompt: Default Prompt
  • File Content Strategy: Full file content
  • Output Template: Repository PR Template
  • Event Trigger: pull_request.opened
  • Correlation ID: 86eace40-a24e-11f1-9471-a4df519a42e0

@Schmarvinius Schmarvinius changed the title feat: add agw impl feat: add agw impl [EXPERIMENTAL] Aug 27, 2026
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