Skip to content

How to Override Outbound OAuth and Propagate Incoming Authorization Token in AWS Bedrock AgentCore Gateway by Interceptor Lambda?

0
  • I’m trying to propagate an access token from the incoming request through the gateway to the target service.
  • Currently, I have configured the outbound auth as the OAuth client and I want to override the token generated from this authorizer by the token incoming in the gateway request through the interceptor.
  • I have written the following request interceptor, but when the agent invoked the gateway the token didn't propagate to the target and the outbound OAuth token is being used.
  • Is there a configuration step I’m missing that prevents an interceptor from overriding outbound OAuth headers? Or is outbound OAuth always applied after the interceptor runs?
def lambda_handler(event, context):
    mcp_data = event.get('mcp', {})
    gateway_request = mcp_data.get('gatewayRequest', {})
    headers = gateway_request.get('headers', {})
    credentials = headers.get('authorization', '') or headers.get('Authorization', '')

    return {
        "interceptorOutputVersion": "1.0",
        "mcp": {
            "transformedGatewayRequest": {
                "headers": {
                    "Authorization": credentials,
                },
                "body": event['mcp']['gatewayRequest']['body']
            }
        }
    }
1 Answer
0

When outbound OAuth is configured, it is expected to take precedence over any headers set by interceptors. To ensure that an incoming authorization token is propagated to the target service, outbound OAuth must be disabled for the route, or replaced with a custom outbound authentication configuration.

https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/gateway-headers.html#gateway-headers-interceptor-propagation

EXPERT
answered 2 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.