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
Copy file name to clipboardExpand all lines: docs/sql.md
+20-25Lines changed: 20 additions & 25 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,21 +1,23 @@
1
1
# `sqlauth:SQL`
2
2
3
-
4
3
These are authentication modules for authenticating a user against and retrieving attributes from an SQL database.
5
4
6
5
The authentication can be done in one of two ways:
6
+
7
7
- Most commonly, as a part of the SQL query itself (ie. using SQL functions to hash a parameterized password and compare that to a value stored in the database).
8
8
- Less commonly, just store the hash in the database, retrieve that then compare that hash using PHP's `password_verify()` function to authenticate. This is useful in cases where there is minimal support in the database or to allow the same code to work against many databases without modification. The differences in how this is configured are in a section towards the bottom of this file.
9
9
10
10
There are two different configuration formats supported ("version 1" and "version 2"). Version 1 is simpler, but is more limited in functionality. Version 2 is more powerful and configurable, but a little more verbose. If you wish to authenticate or gather attributes from more than one SQL database, or need more than one SQL query for authentication then you definitely need Version 2.
11
11
12
12
The Version 1 configuration support comes in two flavours (but identical configurations):
13
+
13
14
-`sqlauth:SQL` uses the legacy Version 1 configuration format and code. Eventually the old code will be phased out, and `sqlauth:SQL` will become a synonym for `sqlauth:SQL1Compat`.
14
15
-`sqlauth:SQL1Compat` uses the legacy Version 1 configuration, but applies it to the Version 2 code.
15
16
16
17
If you are starting out we recommend the Version 2 (`sqlauth:SQL2`) configuration format.
17
18
18
19
You enable the module in `config/config.php`.
20
+
19
21
```php
20
22
'module.enable' => [
21
23
[...]
@@ -39,9 +41,9 @@ The basic concepts of how `sqlauth` works is common between versions 1 and 2.
39
41
40
42
As a worked example, consider the following example table useful for authentication:
and another table (potentially in a completely separate database) which has attributes we want to return:
47
49
@@ -75,10 +77,10 @@ In summary:
75
77
- If multiple queries return the same column names, they will also be merged into the same attributes.
76
78
- Duplicate values and NULL values will be removed.
77
79
78
-
79
80
## Version 2 Configuration Format
80
81
81
82
The Version 2 configuration format supports:
83
+
82
84
- One or more database connections.
83
85
- One or more authentication queries using any database defined in the `databases` section.
84
86
- Zero or more attribute queries. Each query can use any database defined in the database section, and can be restricted to apply only to one or more authentication queries.
@@ -112,13 +114,12 @@ $config = [
112
114
113
115
Assuming the correct `:username` and `:password` are passed, the resulting SAML attributes returned by this configuration would be:
In the below example, we have users in two separate databases and two authentication queries. Authentication queries are run in the order they are configured, and once an authentication query successfully authenticates a user it is deemed to be authenticated using that query, and no further authentication queries are run. In the below case, the username formats are defined (single lower case word for staff, suppliers have a "supp_" prefix), and as a result we can use the optional `username_regex` parameter to get a slight performance boost out of not running unneccessary queries.
167
167
@@ -211,7 +211,6 @@ An example staff login with the above configuration might result in SAML attribu
The next example shows a case where we have a single database we are authenticating against, but are aggregating attributes from a number of different databases. In such cases it is common that users might login with an email address, however the shared User ID between databases is some other ID. To support this, the `extract_userid` takes the value from this other ID field in the authentication query and makes it available as `:userid` in the attribute queries instead of `:username`.
216
215
217
216
```php
@@ -281,7 +280,6 @@ and a student might look like:
281
280
| course |[ Mathematics ]|
282
281
| year |[ 2 ]|
283
282
284
-
285
283
When you've got more than one authentication query, it is possible to restrict attribute queries to only run for certain authentication queries using the `only_for_auth` attribute query configuration parameter:
286
284
287
285
```php
@@ -360,9 +358,7 @@ and a student might look like:
0 commit comments