Skip to content

Commit da80070

Browse files
committed
GFM
1 parent 785fd7d commit da80070

File tree

1 file changed

+65
-57
lines changed

1 file changed

+65
-57
lines changed

README.md

Lines changed: 65 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -24,46 +24,50 @@ The Authentication middleware takes care of setting up the handling of an inboun
2424

2525
#### Usage
2626

27-
use Symfony\Component\HttpFoundation\Response;
28-
use Symfony\Component\HttpKernel\HttpKernelInterface;
29-
30-
$challenge = function (Response $response) {
31-
// Assumptions that can be made:
32-
// * 401 status code
33-
// * WWW-Authenticate header with a value of "Stack"
34-
//
35-
// Expectations:
36-
// * MAY set WWW-Authenticate header to another value
37-
// * MAY return a brand new response (does not have to be
38-
// the original response)
39-
// * MUST return a response
40-
return $response;
41-
};
42-
43-
$authenticate = function (HttpKernelInterface $app, $anonymous) {
44-
// Assumptions that can be made:
45-
// * The $app can be delegated to at any time
46-
// * The anonymous boolean indicates whether or not we
47-
// SHOULD allow anonymous requests through or if we
48-
// should challenge immediately.
49-
// * Additional state, like $request, $type, and $catch
50-
// should be passed via use statement if they are needed.
51-
//
52-
// Expectations:
53-
// * SHOULD set 'stack.authn.token' attribute on the request
54-
// when authentication is successful.
55-
// * MAY delegate to the passed $app
56-
// * MAY return a custom response of any status (for example
57-
// returning a 302 or 400 status response is allowed)
58-
// * MUST return a response
59-
};
60-
61-
return (new Authentication($app, [
62-
'challenge' => $challenge,
63-
'authenticate' => $authenticate,
64-
'anonymous' => true, // default: false
65-
]))
66-
->handle($request, $type, $catch);
27+
```php
28+
<?php
29+
30+
use Symfony\Component\HttpFoundation\Response;
31+
use Symfony\Component\HttpKernel\HttpKernelInterface;
32+
33+
$challenge = function (Response $response) {
34+
// Assumptions that can be made:
35+
// * 401 status code
36+
// * WWW-Authenticate header with a value of "Stack"
37+
//
38+
// Expectations:
39+
// * MAY set WWW-Authenticate header to another value
40+
// * MAY return a brand new response (does not have to be
41+
// the original response)
42+
// * MUST return a response
43+
return $response;
44+
};
45+
46+
$authenticate = function (HttpKernelInterface $app, $anonymous) {
47+
// Assumptions that can be made:
48+
// * The $app can be delegated to at any time
49+
// * The anonymous boolean indicates whether or not we
50+
// SHOULD allow anonymous requests through or if we
51+
// should challenge immediately.
52+
// * Additional state, like $request, $type, and $catch
53+
// should be passed via use statement if they are needed.
54+
//
55+
// Expectations:
56+
// * SHOULD set 'stack.authn.token' attribute on the request
57+
// when authentication is successful.
58+
// * MAY delegate to the passed $app
59+
// * MAY return a custom response of any status (for example
60+
// returning a 302 or 400 status response is allowed)
61+
// * MUST return a response
62+
};
63+
64+
return (new Authentication($app, [
65+
'challenge' => $challenge,
66+
'authenticate' => $authenticate,
67+
'anonymous' => true, // default: false
68+
]))
69+
->handle($request, $type, $catch);
70+
```
6771

6872
### WwwAuthenticateStackChallenge Middleware
6973

@@ -75,23 +79,27 @@ The WwwAuthenticateStackChallenge middleware takes care of setting up the handli
7579

7680
#### Usage
7781

78-
use Symfony\Component\HttpFoundation\Response;
79-
80-
$challenge = function (Response $response) {
81-
// Assumptions that can be made:
82-
// * 401 status code
83-
// * WWW-Authenticate header with a value of "Stack"
84-
//
85-
// Expectations:
86-
// * MAY set WWW-Authenticate header to another value
87-
// * MAY return a brand new response (does not have to be
88-
// the original response)
89-
// * MUST return a response
90-
return $response;
91-
};
92-
93-
return (new WwwAuthenticateStackChallenge($app, $challenge))
94-
->handle($request, $type, $catch);
82+
```php
83+
<?php
84+
85+
use Symfony\Component\HttpFoundation\Response;
86+
87+
$challenge = function (Response $response) {
88+
// Assumptions that can be made:
89+
// * 401 status code
90+
// * WWW-Authenticate header with a value of "Stack"
91+
//
92+
// Expectations:
93+
// * MAY set WWW-Authenticate header to another value
94+
// * MAY return a brand new response (does not have to be
95+
// the original response)
96+
// * MUST return a response
97+
return $response;
98+
};
99+
100+
return (new WwwAuthenticateStackChallenge($app, $challenge))
101+
->handle($request, $type, $catch);
102+
```
95103

96104

97105
License

0 commit comments

Comments
 (0)