I have run into this problem a number of times when using the OAuth2 policy for token validation. The issue seems to be that when validation fails and a 401 should be returned it is essentially raising an exception to short circuit the rest of the policies. This seems to include the response for a proxy end point. I added the AddCORS policy to the response and it doesn’t appear to be executed.
When the token is valid I had to add the Preflight Options check and that fixed normal usage. And this works.
My question is: Is there any way to execute the AddCORs policy for the response when the token is expired?
I had read a little bit about changing/writing my own policy to perform validation to change how it proceeds upon exception, but I was hoping to avoid this path. Is this the way I need to proceed?
If you put the AddCORS policy before your Oauth Verify policy it should still execute. However, once it hits the OAuth policy, it will return a 401, even and especially before hitting your backend.
Thanks I will give it a shot!
hey guys, I implemented something like that and it served me correctly.
In the proxy enpoint we must place in the preflow the next call of a Flowcallout to invoke a sharedflow which will have the policy of CORS
FC-CORS
FC-OAuth2
Definition of flowcallout, where we invoke the sharedflow
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
FC-CORS
OPTIONS-CORS-Headers-Response
definition of sharedflow
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
OPTIONS-CORS-Headers-Response
request.verb == "OPTIONS"
definition of the policy of raisefull, where we will indicate the headers of Access-Control-Allow-Origin with * that will allow the invocation from our browser
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
OPTIONS CORS Headers Response
*
origin, x-requested-with, accept, ucsb-api-key, ucsb-api-version, authorization
3628800
GET, PUT, POST, DELETE
200
OK
true
angular:
const httpOptions2= { headers:newHttpHeaders({ ‘Authorization’:‘Bearer token’ }) };
obtenerCatalogos():Observable { return this.httpClient.get(uriApigee+‘endpointapigee’,httpOptions2); }
Regars