-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
Only Authenticating for certain urls in api key authentication #3815
Comments
I solved it in security.yml creating an excluding regex for the pattern, using the example above: security:
...
firewalls:
secured_area:
pattern: ^/(?!login\/check) I like the approach better also because this is a security matter, so not having to add the url inside the ApiKeyAuthentication class seems a good deal. |
Hi @javaguirre! Your solution sounds good, but I'm not totally sure it should work - but obviously, you have it working, so I'm trying to understand :). If you authenticate at Because I think your original report may be valid. The And as you can see, the So basically, I think you're right, but I'm not sure immediately what the proper solution is. Your solution doesn't make logical sense to me, but if you want to explain it further, it could be legitimate :). Thanks! |
I'll work on a solution, thank you for your answer. :-) |
I ran up against this today, and kind of hacked my way around it by - in the case where I don't want to authenticate a particular URL - setting an empty 'api key' on the token returned by It would certainly be nice to have a 'canonical' way of doing this, because as noted the current advice in the docs under 'Only Authenticating for Certain URLs' doesn't work! |
I believe a proposed fix for this is at symfony/symfony#11414. |
Using this: public function createToken(Request $request, $providerKey)
For me returns : "A Token was not found in the SecurityContext." How i can solve this? put on authenticateToken method: ???? |
@cirovargas @peterrehm has a workaround here: symfony/symfony#11490 (comment) |
I have wrote this code http://symfony.com/doc/current/cookbook/security/api_key_authentication.html#cookbook-security-api-key-config And now when I ran something like this: app/login/check?apiKey=mihai I receive:cNotFoundHttpException: No route found for "GET /app/login/check". My config is:
); Could someone help me? |
Hi there? Just create a route for /app/login/check. It doesn't need to do anything - the controller won't be called, but it has to exist. Cheers! |
Hi @weaverryan , }); |
If you submit your form, this should result in a POST request to that URL, and then the security system will intercept it (so it won't even hit your controller). If you just surf to the URL, you'll get an error - but people will only submit the login form to get here (make sure you have method=POST on your login form) |
@weaverryan And my config is: $app->register(
); |
In the final I have manage to do it. $app->match('/app/login/api/check', function() use ($app) {
}); |
I think this part is not valid, It couldn't work.
http://symfony.com/doc/current/cookbook/security/api_key_authentication.html#only-authenticating-for-certain-urls
If you just do this:
The Token is null and then authenticate won't work because needs an instance of Symfony\Component\Security\Core\Authentication\Token\TokenInterface. The exact error is:
It happens here:
https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Security/Http/Firewall/SimplePreAuthenticationListener.php#L77-L80
I am trying to sort things out. :-)
Thank you in advance!
The text was updated successfully, but these errors were encountered: