You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 29, 2020. It is now read-only.
Copy file name to clipboardExpand all lines: docs/book/v1/user-repository.md
+79Lines changed: 79 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -42,3 +42,82 @@ result will be a `UserInterface` instance, otherwise a null value is returned.
42
42
The second function is `getRolesFromUser()` and it specifies how to retrieve
43
43
the roles for a user. If a user does not have roles, this function will return
44
44
an empty array.
45
+
46
+
47
+
## Configure the user repository
48
+
49
+
In order to use a user repository adapter, we need to configure it. For instance,
50
+
to consume an `htpasswd` file, we need to configure the path to the file.
51
+
Such configuration is provided in the `authentication` hierarchy provided to
52
+
your [PSR-11](http://www.php-fig.org/psr/psr-11/) container. We demonstrate
53
+
examples of such configuration below.
54
+
55
+
Using [Expressive](https://docs.zendframework.com/zend-expressive/), this
56
+
configuration can be stored in a file under the `/config/autoload/` folder. We
57
+
suggest to use a `.local.php` suffix — e.g.
58
+
`/config/autoload/auth.local.php`— as local configuration is not stored
59
+
in the version control system.
60
+
61
+
You can also provide this configuration using a [ConfigProvider.php](https://github.com/zendframework/zend-expressive-authentication/blob/master/src/ConfigProvider.php)
62
+
class. [Read this blog post](https://framework.zend.com/blog/2017-04-20-config-aggregator.html)
63
+
for more information on config providers.
64
+
65
+
## htpasswd configuration
66
+
67
+
When using the htpasswd user repository implementation, you need only configure
68
+
the path to the `htpasswd` file:
69
+
70
+
```php
71
+
return [
72
+
'authentication' => [
73
+
'htpasswd' => 'insert the path to htpasswd file',
74
+
],
75
+
];
76
+
```
77
+
78
+
## PDO configuration
79
+
80
+
When using the PDO user repository adapter, you will need to provide PDO
81
+
connection parameters, as well as information on the table, field names, and a
82
+
SQL statement for retrieiving user roles:
83
+
84
+
```php
85
+
return [
86
+
'authentication' => [
87
+
'pdo' => [
88
+
'dsn' => '',
89
+
'username' => '',
90
+
'password' => '',
91
+
'table' => 'user table name',
92
+
'field' => [
93
+
'identity' => 'identity field name',
94
+
'password' => 'password field name',
95
+
],
96
+
'sql_get_roles' => 'SQL to retrieve roles with :identity parameter',
97
+
],
98
+
],
99
+
];
100
+
```
101
+
102
+
The required parameters are `dsn`, `table`, and `field`.
103
+
104
+
The `dsn` value is the DSN connection string to be used to connect to the database.
105
+
For instance, using a SQLite database, a typical value is `sqlite:/path/to/file`.
106
+
107
+
The `username` and `password` parameters are optional parameters used to connect
108
+
to the database. Depending on the database, these parameters may not be required;
109
+
e.g. [SQLite](https://sqlite.org/) does not require them.
110
+
111
+
The `table` value is the name of the table containing the user credentials.
112
+
113
+
The `field` parameter contains the field name of the `identity` of the user and
114
+
the user `password.` The `identity` of the user can be a username, an email, etc.
115
+
116
+
The `sql_get_roles` setting is an optional parameter that contains the SQL query
117
+
for retrieving the user roles. The identity value must be specified using the
118
+
placeholder `:identity`. For instance, if a role is stored in a user table, a
0 commit comments