Skip to content

Commit 48b575f

Browse files
committedAug 3, 2023
update
1 parent 5be7db5 commit 48b575f

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
 

‎README.md

+26
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,7 @@ You can enable the following middleware using the "middlewares" config parameter
664664
- "apiKeyAuth": Support for "API Key Authentication"
665665
- "apiKeyDbAuth": Support for "API Key Database Authentication"
666666
- "dbAuth": Support for "Database Authentication"
667+
- "wpAuth": Support for "Wordpress Authentication"
667668
- "jwtAuth": Support for "JWT Authentication"
668669
- "basicAuth": Support for "Basic Authentication"
669670
- "reconnect": Reconnect to the database with different parameters
@@ -716,6 +717,10 @@ You can tune the middleware behavior using middleware specific configuration par
716717
- "dbAuth.loginAfterRegistration": 1 or zero if registered users should be logged in after registration ("")
717718
- "dbAuth.passwordLength": Minimum length that the password must have ("12")
718719
- "dbAuth.sessionName": The name of the PHP session that is started ("")
720+
- "wpAuth.mode": Set to "optional" if you want to allow anonymous access ("required")
721+
- "wpAuth.wpDirectory": The folder/path where the Wordpress install can be found (".")
722+
- "wpAuth.usernameFormField": The name of the form field that holds the username ("username")
723+
- "wpAuth.passwordFormField": The name of the form field that holds the password ("password")
719724
- "jwtAuth.mode": Set to "optional" if you want to allow anonymous access ("required")
720725
- "jwtAuth.header": Name of the header containing the JWT token ("X-Authorization")
721726
- "jwtAuth.leeway": The acceptable number of seconds of clock skew ("5")
@@ -841,6 +846,27 @@ For login operations, it is possible to use a view as the usersTable. Such view
841846

842847
However, views with joined tables are not insertable ([see issue 907](https://github.com/mevdschee/php-crud-api/issues/907) ). As a workaround, use the property ***loginTable*** to set a different reference table for login. The **usersTable** will still be set to the normal, insertable users table.
843848

849+
#### Wordpress authentication
850+
851+
The Wordpress authentication middleware defines three routes:
852+
853+
method path - parameters - description
854+
---------------------------------------------------------------------------------------------------
855+
GET /me - - returns the user that is currently logged in
856+
POST /login - username, password - logs a user in by username and password
857+
POST /logout - - logs out the currently logged in user
858+
859+
A user can be logged in by sending it's username and password to the login endpoint (in JSON format).
860+
The user can be logged out by sending a POST request with an empty body to the logout endpoint.
861+
In the authorization middleware you can use functions:
862+
863+
- wp_get_current_user()
864+
- is_user_logged_in()
865+
- is_super_admin()
866+
- user_can(wp_get_current_user(),'edit_posts');
867+
868+
Play with it and let me know how you like it.. :-)
869+
844870

845871
#### Basic authentication
846872

0 commit comments

Comments
 (0)