I’m trying to allow CORS from my API so that a minimalist test piece of Javascript can play around with sending Google auth tokens. I have “Add CORS” sitting on my TargetEndPoint PreFlow and it appears to work. Access-Control-Allow-Origin comes through as *, I have a OptionPreFlight flow set up on the Proxy Endpoint as detailed here: http://docs.apigee.com/api-services/content/adding-cors-support-api-proxy and all is right with the world.
However, all is only right when I disable the “Verify OAuth v2.0 Access Token” and “Remove Header Authorization” policies that were attached to the Proxy EndPoint PreFlow when I first configured the API Proxy. When they are there I get “CORS header ‘Access-Control-Allow-Origin’ missing” and when they are gone I get straight through to the API that is being proxied.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ProxyEndpoint name="default">
<Description/>
<FaultRules/>
<PreFlow name="PreFlow">
<Request>
<Step>
<Name>verify-oauth-v2-access-token</Name>
</Step>
<Step>
<Name>remove-header-authorization</Name>
</Step>
</Request>
<Response>
</Response>
</PreFlow>
<PostFlow name="PostFlow">
<Request/>
<Response/>
</PostFlow>
<Flows>
<Flow name="OptionsPreFlight">
<Request/>
<Response>
<Step>
<Name>add-cors</Name>
</Step>
</Response>
<Condition>request.verb == "OPTIONS"</Condition>
</Flow>
</Flows>
<HTTPProxyConnection>
<BasePath>/niwaweather-authed</BasePath>
<Properties/>
<VirtualHost>secure</VirtualHost>
</HTTPProxyConnection>
<RouteRule name="NoRoute">
<Condition>request.verb == "OPTIONS"</Condition>
</RouteRule>
<RouteRule name="default">
<TargetEndpoint>default</TargetEndpoint>
</RouteRule>
</ProxyEndpoint>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<TargetEndpoint name="default">
<Description/>
<FaultRules/>
<PreFlow name="PreFlow">
<Request/>
<Response>
<Step>
<Name>add-cors</Name>
</Step>
</Response>
</PreFlow>
<PostFlow name="PostFlow">
<Request/>
<Response/>
</PostFlow>
<Flows/>
<HTTPTargetConnection>
<Properties/>
<URL>https://weather.niwa.co.nz</URL>
</HTTPTargetConnection>
</TargetEndpoint>