New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
allow OPTIONS request without ApiKey #52
Comments
You could try using header instead of querystring
|
@rochamarcelo I know how to set up to accept the ApiKey in the header. My problem is that the first OPTIONS preflight request does not contain the ApiKey header, so the request is redirected. So what I would need is allowing OPTIONS requests to the application without the ApiKey. |
It seems that you need a custom authorization rule for it, I'm not sure if this is a generic case. |
Can you give me a hint how to do that? |
@rrd108 please try to add a CorsMiddleware like this one https://github.com/ozee31/cakephp-cors/blob/master/src/Routing/Middleware/CorsMiddleware.php This should handle the OPTIONS request without having to add custom authorization rules. Please let us know if this works for you. |
As I see there is official support for this. Am I right? Addind OPTIONS to |
It seems similar to how the mentioned middleware works, but instead of using named methods like allowHeaders it uses withHeader method |
hm... it still refuses option requests |
Have you followed the plugin installation steps, it requires some config keys https://github.com/ozee31/cakephp-cors#configuration |
the problem is that options request does not contain the apikey, so they are refused by the plugin |
@rrd108 if you check the mentioned behavior, the response for OPTIONS request is handled at https://github.com/ozee31/cakephp-cors/blob/master/src/Routing/Middleware/CorsMiddleware.php#L23 So, using that behavior the OPTIONS requestt will not go to controller layer but just return a simple response. If you tried to use that behavior and did not worked please debug the IF conditions. |
closing this one, if the issue persists please reopen |
I use ApiKey authentication for a vuejs frontend application, haveing CakePHP at the backend. At first the user give his email and password to identify himself and in the response he gets his ApiKey, and all later requests happens by ApiKey authentication - currently as a query string parameter.
I want to use it as a header instead of the query string.
The problem is the following. When I send an ajax request to the backend it sends OPTIONS request without the ApiKey header. It is because by CORS policy it will send a preflight requests. Perhaps because the ApiKey header is missing the backend sends back a 302 response instead of the actual content.
So what I would need is allowing OPTIONS requests to the application without the ApiKey.
The text was updated successfully, but these errors were encountered: