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

Commit 01e8680

Browse files
committed
Split docs into three pages
- Intro for package introduction - Configuration - Usage
1 parent 144405a commit 01e8680

File tree

4 files changed

+90
-90
lines changed

4 files changed

+90
-90
lines changed

docs/book/v1/config.md

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Configuration
2+
3+
To use the adapter, you will need to provide the following configuration:
4+
5+
- A valid zend-expressive-authentication `UserRepositoryInterface` service in
6+
your DI container. This service will perform the actual work of validating the
7+
supplied credentials.
8+
9+
- An HTTP Basic **realm**. This may be an arbitrary value, but is [required by
10+
the specification](https://tools.ietf.org/html/rfc7617#section-2).
11+
12+
- A response factory. If you are using Expressive, this is already configured
13+
for you.
14+
15+
As an example of configuration:
16+
17+
```php
18+
// config/autoload/authentication.global.php
19+
20+
use Zend\Expressive\Authentication\AdapterInterface;
21+
use Zend\Expressive\Authentication\Basic\BasicAccess;
22+
use Zend\Expressive\Authentication\UserRepositoryInterface;
23+
use Zend\Expressive\Authentication\UserRepository\PdoDatabase;
24+
25+
return [
26+
'dependencies' => [
27+
'aliases' => [
28+
// Use the default PdoDatabase user repository. This assumes
29+
// you have configured that service correctly.
30+
UserRepositoryInterface::class => PdoDatabase::class,
31+
32+
// Tell zend-expressive-authentication to use the BasicAccess
33+
// adapter:
34+
AdapterInterface::class => BasicAccess::class,
35+
],
36+
],
37+
'authentication' => [
38+
'realm' => 'api',
39+
],
40+
];
41+
```

docs/book/v1/intro.md

-90
Original file line numberDiff line numberDiff line change
@@ -16,93 +16,3 @@ the supplied credentials**.
1616
> Since HTTP Basic transmits the credentials via the URL, it should only be used
1717
> within trusted networks, and never in public-facing sites, as the URL can be
1818
> 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, // use your own handler here
106-
]
107-
);
108-
```

docs/book/v1/usage.md

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Usage
2+
3+
Whenever you need an authenticated user, you can place the
4+
zend-expressive-authentication `AuthenticationMiddleware` in your pipeline.
5+
6+
## Globally
7+
8+
If you need all routes to use authentication, add it globally.
9+
10+
```php
11+
// In config/pipeline.php, within the callback:
12+
13+
$app->pipe(Zend\Expressive\Authentication\AuthenticationMiddleware::class);
14+
```
15+
16+
## For an entire sub-path
17+
18+
If you need all routes that begin with a particular sub-path to require
19+
authentication, use [path-segregation](https://docs.zendframework.com/zend-stratigility/v3/api/#path):
20+
21+
```php
22+
// In config/pipeline.php.
23+
// In the import statements:
24+
use Zend\Expressive\Authentication\AuthenticationMiddleware;
25+
26+
// In the callback:
27+
$app->pipe('/api', $factory->path(
28+
$factory->prepare(AuthenticationMiddleware::class)
29+
));
30+
```
31+
32+
## For a specific route
33+
34+
If you want to restrict access for a specific route, create a [route-specific
35+
middleware pipeline](https://docs.zendframework.com/zend-expressive/v3/cookbook/route-specific-pipeline/):
36+
37+
```php
38+
// In config/routes.php, in the callback:
39+
40+
$app->get(
41+
'/path/requiring/authentication',
42+
[
43+
Zend\Expressive\Authentication\AuthenticationMiddleware::class,
44+
HandlerRequiringAuthentication::class, // use your own handler here
45+
]
46+
);
47+
```

mkdocs.yml

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ site_dir: docs/html
33
pages:
44
- Home: index.md
55
- Introduction: v1/intro.md
6+
- Configuration: v1/config.md
7+
- Usage: v1/usage.md
68
- "_hidden-legacy-page-links":
79
- "_intro": intro.md
810
site_name: zend-expressive-authentication-basic

0 commit comments

Comments
 (0)