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: README.md
+43-9Lines changed: 43 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -132,7 +132,7 @@ The following features are supported:
132
132
- Binary fields supported with base64 encoding
133
133
- Spatial/GIS fields and filters supported with WKT and GeoJSON
134
134
- Generate API documentation using OpenAPI tools
135
-
- Authentication via JWT token or username/password
135
+
- Authentication via API key, JWT token or username/password
136
136
- Database connection parameters may depend on authentication
137
137
- Support for reading database structure in JSON
138
138
- Support for modifying database structure using REST endpoint
@@ -627,6 +627,8 @@ You can enable the following middleware using the "middlewares" config parameter
627
627
- "cors": Support for CORS requests (enabled by default)
628
628
- "xsrf": Block XSRF attacks using the 'Double Submit Cookie' method
629
629
- "ajaxOnly": Restrict non-AJAX requests to prevent XSRF attacks
630
+
- "apiKeyAuth": Support for "API Key Authentication"
631
+
- "apiKeyDbAuth": Support for "API Key Database Authentication"
630
632
- "dbAuth": Support for "Database Authentication"
631
633
- "jwtAuth": Support for "JWT Authentication"
632
634
- "basicAuth": Support for "Basic Authentication"
@@ -659,6 +661,13 @@ You can tune the middleware behavior using middleware specific configuration par
659
661
- "ajaxOnly.excludeMethods": The methods that do not require AJAX ("OPTIONS,GET")
660
662
- "ajaxOnly.headerName": The name of the required header ("X-Requested-With")
661
663
- "ajaxOnly.headerValue": The value of the required header ("XMLHttpRequest")
664
+
- "apiKeyAuth.mode": Set to "optional" if you want to allow anonymous access ("required")
665
+
- "apiKeyAuth.header": The name of the API key header ("X-API-Key")
666
+
- "apiKeyAuth.keys": List of API keys that are valid ("")
667
+
- "apiKeyDbAuth.mode": Set to "optional" if you want to allow anonymous access ("required")
668
+
- "apiKeyDbAuth.header": The name of the API key header ("X-API-Key")
669
+
- "apiKeyDbAuth.usersTable": The table that is used to store the users in ("users")
670
+
- "apiKeyDbAuth.apiKeyColumn": The users table column that holds the API key ("api_key")
662
671
- "dbAuth.mode": Set to "optional" if you want to allow anonymous access ("required")
663
672
- "dbAuth.usersTable": The table that is used to store the users in ("users")
664
673
- "dbAuth.usernameColumn": The users table column that holds usernames ("username")
@@ -718,18 +727,43 @@ In the sections below you find more information on the built-in middleware.
718
727
719
728
### Authentication
720
729
721
-
Currently there are three types of authentication supported. They all store the authenticated user in the `$_SESSION` super global.
730
+
Currently there are five types of authentication supported. They all store the authenticated user in the `$_SESSION` super global.
722
731
This variable can be used in the authorization handlers to decide wether or not sombeody should have read or write access to certain tables, columns or records.
723
732
The following overview shows the kinds of authentication middleware that you can enable.
724
733
725
-
| Name | Middleware | Authenticated via | Users are stored in | Session variable |
Below you find more information on each of the authentication types.
732
743
744
+
#### API key authentication
745
+
746
+
API key authentication works by sending an API key in a request header.
747
+
The header name defaults to "X-API-Key" and can be configured using the 'apiKeyAuth.header' configuration parameter.
748
+
Valid API keys must be configured using the 'apiKeyAuth.keys' configuration parameter (comma seperated list).
749
+
750
+
X-API-Key: 02c042aa-c3c2-4d11-9dae-1a6e230ea95e
751
+
752
+
The authenticated API key will be stored in the `$_SESSION['apiKey']` variable.
753
+
754
+
Note that the API key authentication does not require or use sessions (cookies).
755
+
756
+
#### API key database authentication
757
+
758
+
API key database authentication works by sending an API key in a request header "X-API-Key" (the name is configurable).
759
+
Valid API keys are read from the database from the column "api_key" of the "users" table (both names are configurable).
760
+
761
+
X-API-Key: 02c042aa-c3c2-4d11-9dae-1a6e230ea95e
762
+
763
+
The authenticated user will be stored in the `$_SESSION['apiUser']` variable.
764
+
765
+
Note that the API key database authentication does not require or use sessions (cookies).
766
+
733
767
#### Database authentication
734
768
735
769
The database authentication middleware defines three new routes:
@@ -746,7 +780,7 @@ A user can be logged in by sending it's username and password to the login endpo
746
780
The authenticated user (with all it's properties) will be stored in the `$_SESSION['user']` variable.
747
781
The user can be logged out by sending a POST request with an empty body to the logout endpoint.
748
782
The passwords are stored as hashes in the password column in the users table. You can register a new user
749
-
using the register endpoint, but this functionality must be turned on using the "dbAuth.regsiterUser"
783
+
using the register endpoint, but this functionality must be turned on using the "dbAuth.registerUser"
750
784
configuration parameter.
751
785
752
786
It is IMPORTANT to restrict access to the users table using the 'authorization' middleware, otherwise all
@@ -762,7 +796,7 @@ Note that this middleware uses session cookies and stores the logged in state on
762
796
#### Basic authentication
763
797
764
798
The Basic type supports a file (by default '.htpasswd') that holds the users and their (hashed) passwords separated by a colon (':').
765
-
When the passwords are entered in plain text they fill be automatically hashed.
799
+
When the passwords are entered in plain text they will be automatically hashed.
766
800
The authenticated username will be stored in the `$_SESSION['username']` variable.
767
801
You need to send an "Authorization" header containing a base64 url encoded version of your colon separated username and password, after the word "Basic".
0 commit comments