Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit e3a2f8d

Browse files
committed
Prepare documentation for stable release
- Version documentation - Provide full usage for package
1 parent 55b499e commit e3a2f8d

File tree

3 files changed

+118
-9
lines changed

3 files changed

+118
-9
lines changed

docs/book/intro.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# zend-expressive-authentication-basic
2-
3-
This component provides an HTTP Basic Authentication adapter for
4-
[zend-expressive-authentication](https://docs.zendframework.com/zend-expressive-authentication).
5-
6-
Docs are forthcoming...
1+
<noscript><meta http-equiv="refresh" content="0; url=/zend-expressive-authentication-basic/v1/intro/"></noscript>
2+
<script>
3+
document.addEventListener("DOMContentLoaded", function (event) {
4+
window.location.pathname = '/zend-expressive-authentication-basic/v1/intro/';
5+
});
6+
</script>

docs/book/v1/intro.md

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# zend-expressive-authentication-basic
2+
3+
This component provides an HTTP Basic Authentication adapter for
4+
[zend-expressive-authentication](https://docs.zendframework.com/zend-expressive-authentication).
5+
6+
HTTP Basic authentication utilizes the user-info section of the URL authority in
7+
order to provide credentials. While the HTTP specifications allow a single value
8+
for the user-info, most implementations require a `:`-separated credential, with
9+
the username first, and the password second; in fact, this is how browsers
10+
always send HTTP Basic credentials, as their prompts are always for the two
11+
values. As such, **this implementation expects both a username and password in
12+
the supplied credentials**.
13+
14+
> ### Only use in trusted networks
15+
>
16+
> Since HTTP Basic transmits the credentials via the URL, it should only be used
17+
> within trusted networks, and never in public-facing sites, as the URL can be
18+
> sniffed by MITM proxies.
19+
20+
## Configuration
21+
22+
To use the adapter, you will need to provide the following configuration:
23+
24+
- A valid zend-expressive-authentication `UserRepositoryInterface` service in
25+
your DI container. This service will perform the actual work of validating the
26+
supplied credentials.
27+
28+
- An HTTP Basic **realm**. This may be an arbitrary value, but is [required by
29+
the specification](https://tools.ietf.org/html/rfc7617#section-2).
30+
31+
- A response factory. If you are using Expressive, this is already configured
32+
for you.
33+
34+
As an example of configuration:
35+
36+
```php
37+
// config/autoload/authentication.global.php
38+
39+
use Zend\Expressive\Authentication\AdapterInterface;
40+
use Zend\Expressive\Authentication\Basic\BasicAccess;
41+
use Zend\Expressive\Authentication\UserRepositoryInterface;
42+
use Zend\Expressive\Authentication\UserRepository\PdoDatabase;
43+
44+
return [
45+
'dependencies' => [
46+
'aliases' => [
47+
// Use the default PdoDatabase user repository. This assumes
48+
// you have configured that service correctly.
49+
UserRepositoryInterface::class => PdoDatabase::class,
50+
51+
// Tell zend-expressive-authentication to use the BasicAccess
52+
// adapter:
53+
AdapterInterface::class => BasicAccess::class,
54+
],
55+
],
56+
'authentication' => [
57+
'realm' => 'api',
58+
],
59+
];
60+
```
61+
62+
## Usage
63+
64+
Whenever you need an authenticated user, you can place the
65+
zend-expressive-authentication `AuthenticationMiddleware` in your pipeline.
66+
67+
### Globally
68+
69+
If you need all routes to use authentication, add it globally.
70+
71+
```php
72+
// In config/pipeline.php, within the callback:
73+
74+
$app->pipe(Zend\Expressive\Authentication\AuthenticationMiddleware::class);
75+
```
76+
77+
### For an entire sub-path
78+
79+
If you need all routes that begin with a particular sub-path to require
80+
authentication, use [path-segregation](https://docs.zendframework.com/zend-stratigility/v3/api/#path):
81+
82+
```php
83+
// In config/pipeline.php.
84+
// In the import statements:
85+
use Zend\Expressive\Authentication\AuthenticationMiddleware;
86+
87+
// In the callback:
88+
$app->pipe('/api', $factory->path(
89+
$factory->prepare(AuthenticationMiddleware::class)
90+
));
91+
```
92+
93+
### For a specific route
94+
95+
If you want to restrict access for a specific route, create a [route-specific
96+
middleware pipeline](https://docs.zendframework.com/zend-expressive/v3/cookbook/route-specific-pipeline/):
97+
98+
```php
99+
// In config/routes.php, in the callback:
100+
101+
$app->get(
102+
'/path/requiring/authentication',
103+
[
104+
Zend\Expressive\Authentication\AuthenticationMiddleware::class,
105+
HandlerRequiringAuthentication::class,
106+
]
107+
);
108+
```

mkdocs.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
docs_dir: docs/book
22
site_dir: docs/html
33
pages:
4-
- index.md
5-
- Introduction: intro.md
4+
- Home: index.md
5+
- Introduction: v1/intro.md
6+
- "_hidden-legacy-page-links":
7+
- "_intro": intro.md
68
site_name: zend-expressive-authentication-basic
79
site_description: 'HTTP Basic Authentication adapter for zend-expressive-authentication.'
810
repo_url: 'https://github.com/zendframework/zend-expressive-authentication-basic'
9-
copyright: 'Copyright (c) 2017 <a href="http://www.zend.com/">Zend Technologies USA Inc.</a>'

0 commit comments

Comments
 (0)