@@ -22,8 +22,10 @@ tasks:
2222
2323 * If the ` stack.authn.token ` is set, it wraps the application in
2424 ` WwwAuthenticateStackChallenge ` and delegates.
25- * If the there is an ` authorization ` header, it returns the result of then
26- ** authenticate** callback.
25+ * Checks the request by calling the ** check** callback. The return value is a
26+ boolean. If true, the ** authenticate** callback is called and its return
27+ value is returned. If false, we should not. The default check is to see if
28+ there is an Authorization header.
2729 * If anonymous requests are received and anonymous requests are allowed, it
2830 wraps the application in ` WwwAuthenticateStackChallenge ` and delegates.
2931 * Otherwise, it returns the result of the ** challenge** callback.
@@ -36,6 +38,18 @@ tasks:
3638use Symfony\Component\HttpFoundation\Response;
3739use Symfony\Component\HttpKernel\HttpKernelInterface;
3840
41+ $check = function (
42+ Request $request,
43+ $type = HttpKernelInterface::MASTER_REQUEST,
44+ $catch = true
45+ ) {
46+ // This is the default 'check' callback if a check callback is not defined.
47+ // This is here merely for demonstration purposes; if authentication relies
48+ // on the existence of an 'authorization' header a 'check' callback does not
49+ // need to be defined.
50+ return $request->headers->has('authorization');
51+ };
52+
3953$challenge = function (Response $response) {
4054 // Assumptions that can be made:
4155 // * 401 status code
@@ -69,6 +83,7 @@ $authenticate = function (HttpKernelInterface $app, $anonymous) {
6983
7084return (new Authentication($app, [
7185 'challenge' => $challenge,
86+ 'check' => $check,
7287 'authenticate' => $authenticate,
7388 'anonymous' => true, // default: false
7489 ]))
0 commit comments