-
Notifications
You must be signed in to change notification settings - Fork 62
Add authentication support to user context subscriber #167
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
Conversation
|
Does it make sense to separate the different authentication mechanisms (OAuth2, HTTP) or should we just check generically on whether an |
|
i would vote for a simpler approach in the sense of what varnish is doing: just check if a Authorization header exists and if so consider the request not anonymous. no configuration, no options. this is the expected behaviour to me, and if i need to tweak that i would extend the subscriber class to change the behaviour |
|
@sprain and thanks a lot for your contribution! i appreciate that. |
|
Simplifying sounds good ;) Will look at it. |
|
Ok, I have simplified this. Any feedbacks? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets do if ($request->server->has('HTTP_AUTHORIZATION') ... rather than loop through all the headers.
looking at the ServerBag::getHeaders method, i have the impression that the safe thing to do would be to check for any of the headers AUTHORIZATION, HTTP_AUTHORIZATION or PHP_AUTH_USER and consider the request not anonymous if any of those headers is present.
|
can you please add some tests like https://github.com/FriendsOfSymfony/FOSHttpCache/blob/master/tests/Unit/SymfonyCache/UserContextSubscriberTest.php#L120 but with AUTHORIZATION headers instead of session cookie? the anonymous case is already covered, but we should have a test where we do have one of these headers and end up being not anonymous. |
|
Updated, please have a look. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is this doing? and why not just pass true literally?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be honest: I have no idea. I just tried to adjust the very complicated existing test from the session approach.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Argument $catch can be removed.
|
coming good, thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CS: please take the last ) on the same line as the {, so that we have ) {
|
@dbu Where is the cookie header removed completely? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need a mock here: just construct a Response object directly with the context header.
|
@ddeboer unless i misread https://github.com/sprain/FOSHttpCache/blob/master/src/SymfonyCache/UserContextSubscriber.php#L226 severely, there never is a cookie header on the hash lookup request, unless we manually set it in that method where i commented (and then removed my comments because i thought it less confusing.) |
|
@ddeboer Updated. |
|
@sprain can you please add a cookie header in the test (with a cookie that is not a session cookie), and assert that there is no cookie header in the hash lookup? if the basic auth header is copied along, i fear the cookie header might actually be copied as well... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assertCount is shorter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 for assertCount - its also more expressive when failing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ddeboer done
|
@dbu Looks good to me now. Let’s merge? |
|
looks good! so the cookie is not propagated. good we have a test that proves it. now the last thing that is missing is the doc. @sprain can you please update https://github.com/FriendsOfSymfony/FOSHttpCache/blob/master/doc/symfony-cache-configuration.rst#user-context accordingly? right now its rather implicit that there is only session with cookies support - we should make it explicit that it can be both basic auth or a session cookie. think you manage that one? otherwise i can have a go at that. |
|
@dbu Updated the docs. Please have a look at contents and format. I am not skilled with rst as I much more often use markdown. |
doc/symfony-cache-configuration.rst
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/php/PHP/
|
looks good to me. the spellchecker complains about |
|
@dbu Updated to |
This is a draft for #147, feedback is welcome! Tests will be added once the approach is accepted (I am new to all this caching stuff).
everything below is obsolete
I added the functionality to determine whether a request is anonymous based on session, basic authentication or oAuth2.
In my Symfony2 app, to only use oAuth2, I would overwrite
getDefaultSubscribersin my own cache class like this: