Just checking - the “Authentication basic token” I guess is HTTP Basic Authentication, something like
Authorization: Basic <BASE64-BLOB-HERE>
Is that right? We don’t call that blob thing a token. It may seem to be strange terminology, but it’s not a token.
ANYWAY…
To get to the point of your question, When invoking any endpoint from an AJAX call initiated from a browser, the browser will conform to the Same Origin policy. You may want to look it up, but the basic idea is that a Javascript on a page that is served from domain foo.bar can call back to API endpoints hosted on foo.bar, but cannot call to endpoints hosted elsewhere.
There is an exception, and that is CORS - if the endpoint in question (let’s say an endpoint hosted at yourorg-test.apigee.net ) emits CORS headers in the response, and handles the CORS preflight request correctly, then the browser will allow JavaScripts to invoke endpoints there.
In short, your API needs to support CORS if you want to invoke it from a webpage. Maybe you already knew this, because you mentioned CORS.
Under CORS , there are several important RESPONSE headers that the API Proxy must emit, in order to tell the browser “you can call me, even if the web page was not served from this domain”.
These headers are listed here.
On a POST, the browser will send a “CORS preflight” request which is an OPTIONS call. your API proxy needs to respond to that with the appropriate headers including the Access-Control-Allow-Headers header. That header must contain the name of REQUEST headers allowed by your endpoint. If your AJAX request includes an outbound header named “Authorization” then the Access-Control-Allow-Headers header that is sent back in response to the preflight must include the value “Authorization”. Likewise those CORS headers must be applied to all responses sent by AJAX.
It’s not difficult to do this with AssignMessage - you can do it in the PostFlow. But you need to be clear on which headers to set and which values to apply to them.
if you just want to disable all CORS restrictions, then you can use this AssignMessage policy in the Response PostFlow of your proxy endpoint:
<AssignMessage name="AM-CORSResponse">
<Add>
<Headers>
<Header name="Access-Control-Allow-Origin">*</Header>
<Header name="Access-Control-Allow-Headers">*</Header>
<Header name="Access-Control-Max-Age">3628800</Header>
<Header name="Access-Control-Allow-Methods">OPTIONS, GET, PUT, POST, DELETE</Header>
</Headers>
</Add>
<IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
<AssignTo createNew="false" transport="http" type="response"/>
</AssignMessage>
That says:
“any client from any domain can send me any headers and any verb”.