Skip to content

Commit f1850d6

Browse files
committed
Update to dflydev/stack-authentication, added LICENSE and README
1 parent bddbd88 commit f1850d6

File tree

4 files changed

+136
-16
lines changed

4 files changed

+136
-16
lines changed

LICENSE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2013 Dragonfly Development Inc.
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is furnished
8+
to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.

README.md

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
Firewall Authentication Middleware
2+
==================================
3+
4+
A [Stack][0] middleware providing a simple, configurable firewall concept for
5+
[STACK-2 Authentication][1] compatible middlewares.
6+
7+
8+
Installation
9+
------------
10+
11+
Through [Composer][2] as [dflydev/stack-firewall][3].
12+
13+
14+
Usage
15+
-----
16+
17+
The Firewall middleware is a thin layer over [dflydev/stack-authentication][4]
18+
based STACK-2 Authentication middlewares.
19+
20+
A **firewall* is defined as an array of associatve arrays representing paths
21+
for which an authentication middleware should be concerned.
22+
23+
If a requested path does not match a firewalled path, the firewall delegates the
24+
request to the next layer immediately.
25+
26+
If a requested path matches and authentication is missing or invalid and
27+
anonymous requests are allowed, the request is allowed through the firewall
28+
without setting the `stack.authn.token`.
29+
30+
If a requested path matches and authentication is missing or inavlid and
31+
anonymous requests are NOT allowed, the firewall will challenge immediately.
32+
33+
If no firewall is defined, the assumed configuration is:
34+
35+
[['path' => '/']]
36+
37+
This effectively means that by default the firewall will match all requests
38+
and will not allow anonymous requests resulting in returning a challenge.
39+
40+
41+
```php
42+
<?php
43+
44+
use Symfony\Component\HttpFoundation\Response;
45+
use Symfony\Component\HttpKernel\HttpKernelInterface;
46+
47+
// The firewall is an array of associative arrays containing the rules for which
48+
// the authentication middleware should be concerned.
49+
$firewall = [
50+
['path' => '/', 'anonymous' => true],
51+
['path' => '/protected'],
52+
];
53+
54+
$challenge = function (Response $response) {
55+
// Assumptions that can be made:
56+
// * 401 status code
57+
// * WWW-Authenticate header with a value of "Stack"
58+
//
59+
// Expectations:
60+
// * MAY set WWW-Authenticate header to another value
61+
// * MAY return a brand new response (does not have to be
62+
// the original response)
63+
// * MUST return a response
64+
return $response;
65+
};
66+
67+
$authenticate = function (HttpKernelInterface $app, $anonymous) {
68+
// Assumptions that can be made:
69+
// * The $app can be delegated to at any time
70+
// * The anonymous boolean indicates whether or not we
71+
// SHOULD allow anonymous requests through or if we
72+
// should challenge immediately.
73+
// * Additional state, like $request, $type, and $catch
74+
// should be passed via use statement if they are needed.
75+
//
76+
// Expectations:
77+
// * SHOULD set 'stack.authn.token' attribute on the request
78+
// when authentication is successful.
79+
// * MAY delegate to the passed $app
80+
// * MAY return a custom response of any status (for example
81+
// returning a 302 or 400 status response is allowed)
82+
// * MUST return a response
83+
};
84+
85+
return (new Firewall($app, [
86+
'challenge' => $challenge,
87+
'authenticate' => $authenticate,
88+
'firewall' => $firewall,
89+
]))
90+
->handle($request, $type, $catch);
91+
```
92+
93+
94+
License
95+
-------
96+
97+
MIT, see LICENSE.
98+
99+
100+
Community
101+
---------
102+
103+
If you have questions or want to help out, join us in the **#stackphp** or
104+
**#dflydev** channels on **irc.freenode.net**.
105+
106+
107+
[0]: http://stackphp.com/
108+
[1]: http://stackphp.com/specs/STACK-2/
109+
[2]: http://getcomposer.org
110+
[3]: https://packagist.org/packages/dflydev/stack-firewall

composer.json

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,6 @@
2020
"Dflydev\\Stack": "src"
2121
}
2222
},
23-
"repositories": [
24-
{
25-
"type": "vcs",
26-
"url": "https://github.com/dflydev/dflydev-stack-authentication"
27-
}
28-
],
2923
"require": {
3024
"php": ">=5.4.0",
3125
"dflydev/stack-authentication": "1.0.*@dev",

composer.lock

Lines changed: 7 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)