Skip to content

Commit 3828015

Browse files
committed
Merge branch 'master' of github.com:mevdschee/php-crud-api
2 parents 1bfc8fe + be5ec64 commit 3828015

File tree

101 files changed

+716
-5386
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+716
-5386
lines changed

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
composer.phar
2-
composer.lock
3-
.git
2+
vendor/

README.md

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ These are all the configuration options and their default value between brackets
7070
- "username": Username of the user connecting to the database (no default)
7171
- "password": Password of the user connecting to the database (no default)
7272
- "database": Database the connecting is made to (no default)
73+
- "tables": Comma separated list of tables to publish (defaults to 'all')
7374
- "middlewares": List of middlewares to load (`cors`)
7475
- "controllers": List of controllers to load (`records,geojson,openapi`)
7576
- "openApiBase": OpenAPI info (`{"info":{"title":"PHP-CRUD-API","version":"1.0.0"}}`)
@@ -93,7 +94,7 @@ These limitation and constrains apply:
9394

9495
The following features are supported:
9596

96-
- Single PHP file, easy to deploy.
97+
- Composer install or single PHP file, easy to deploy.
9798
- Very little code, easy to adapt and maintain
9899
- Supports POST variables as input (x-www-form-urlencoded)
99100
- Supports a JSON object as input
@@ -119,10 +120,18 @@ The following features are supported:
119120

120121
## Compilation
121122

123+
You can install all dependencies of this project using the following command:
124+
125+
php install.php
126+
122127
You can compile all files into a single "`api.php`" file using:
123128

124129
php build.php
125130

131+
NB: The install script will patch the dependencies in the vendor directory for PHP 7.0 compatibility.
132+
133+
### Development
134+
126135
You can access the non-compiled code at the URL:
127136

128137
http://localhost:8080/src/records/posts/1
@@ -137,7 +146,7 @@ You can update all dependencies of this project using the following command:
137146

138147
This script will install and run [Composer](https://getcomposer.org/) to update the dependencies.
139148

140-
NB: The update script will also patch the dependencies in the vendor directory for PHP 7.0 compatibility.
149+
NB: The update script will patch the dependencies in the vendor directory for PHP 7.0 compatibility.
141150

142151
## TreeQL, a pragmatic GraphQL
143152

@@ -613,6 +622,7 @@ You can tune the middleware behavior using middleware specific configuration par
613622
- "dbAuth.usernameColumn": The users table column that holds usernames ("username")
614623
- "dbAuth.passwordColumn": The users table column that holds passwords ("password")
615624
- "dbAuth.returnedColumns": The columns returned on successful login, empty means 'all' ("")
625+
- "dbAuth.sessionName": The name of the PHP session that is started ("")
616626
- "jwtAuth.mode": Set to "optional" if you want to allow anonymous access ("required")
617627
- "jwtAuth.header": Name of the header containing the JWT token ("X-Authorization")
618628
- "jwtAuth.leeway": The acceptable number of seconds of clock skew ("5")
@@ -621,13 +631,16 @@ You can tune the middleware behavior using middleware specific configuration par
621631
- "jwtAuth.algorithms": The algorithms that are allowed, empty means 'all' ("")
622632
- "jwtAuth.audiences": The audiences that are allowed, empty means 'all' ("")
623633
- "jwtAuth.issuers": The issuers that are allowed, empty means 'all' ("")
634+
- "jwtAuth.sessionName": The name of the PHP session that is started ("")
624635
- "basicAuth.mode": Set to "optional" if you want to allow anonymous access ("required")
625636
- "basicAuth.realm": Text to prompt when showing login ("Username and password required")
626637
- "basicAuth.passwordFile": The file to read for username/password combinations (".htpasswd")
638+
- "basicAuth.sessionName": The name of the PHP session that is started ("")
627639
- "reconnect.driverHandler": Handler to implement retrieval of the database driver ("")
628640
- "reconnect.addressHandler": Handler to implement retrieval of the database address ("")
629641
- "reconnect.portHandler": Handler to implement retrieval of the database port ("")
630642
- "reconnect.databaseHandler": Handler to implement retrieval of the database name ("")
643+
- "reconnect.tablesHandler": Handler to implement retrieval of the table names ("")
631644
- "reconnect.usernameHandler": Handler to implement retrieval of the database username ("")
632645
- "reconnect.passwordHandler": Handler to implement retrieval of the database password ("")
633646
- "authorization.tableHandler": Handler to implement table authorization rules ("")
@@ -756,11 +769,30 @@ You can also change the `url` variable, used to test the API with authentication
756769
First you need to create a Firebase project on the [Firebase console](https://console.firebase.google.com/).
757770
Add a web application to this project and grab the code snippet for later use.
758771

759-
Then you have to configure the `jwtAuth.secrets` configuration in your `api.php` file.
760-
Grab the public key via this [URL](https://www.googleapis.com/robot/v1/metadata/x509/[email protected]).
761-
There may be several certificates, just grab the one corresponding to your `kid` (if you don't
762-
know what it is, just test them all until you will be logged in).
763-
Now, just fill `jwtAuth.secrets` with your public key.
772+
Then you have to configure the `jwtAuth.secrets` configuration in your `api.php` file.
773+
This can be done as follows:
774+
775+
a. Log a user in to your Firebase-based app, get an authentication token for that user
776+
b. Go to [https://jwt.io/](https://jwt.io/) and paste the token in the decoding field
777+
c. Read the decoded header information from the token, it will give you the correct `kid`
778+
d. Grab the public key via this [URL](https://www.googleapis.com/robot/v1/metadata/x509/[email protected]), which corresponds to your `kid` from previous step
779+
e. Now, just fill `jwtAuth.secrets` with your public key in the `api.php`
780+
781+
Here is an example of what it should look like in the configuration:
782+
783+
```
784+
...,
785+
'middlewares' => 'cors, jwtAuth, authorization',
786+
'jwtAuth.secrets' => "ce5ced6e40dcd1eff407048867b1ed1e706686a0:-----BEGIN CERTIFICATE-----\nMIIDHDCCAgSgAwIBAgIIExun9bJSK1wwDQYJKoZIhvcNAQEFBQAwMTEvMC0GA1UE\nAxMmc2VjdXJldG9rZW4uc3lzdGVtLmdzZXJ2aWNlYWNjb3VudC5jb20wHhcNMTkx\nMjIyMjEyMTA3WhcNMjAwMTA4MDkzNjA3WjAxMS8wLQYDVQQDEyZzZWN1cmV0b2tl\nbi5zeXN0ZW0uZ3NlcnZpY2VhY2NvdW50LmNvbTCCASIwDQYJKoZIhvcNAQEBBQAD\nggEPADCCAQoCggEBAKsvVDUwXeYQtySNvyI1/tZAk0sj7Zx4/1+YLUomwlK6vmEd\nyl2IXOYOj3VR7FBA24A9//nnrp+mV8YOYEOdaWX7PQo0PIPFPqdA0r7CqBUWHPfQ\n1WVHVRQY3G0c7upM97UfMes9xOrMqyvecMRk1e5S6eT12Zh2og7yiVs8gP83M1EB\nGqseUaltaadjyT35w5B0Ny0/7NdLYiv2G6Z0S821SxvSo1/wfmilnBBKYYluP0PA\n9NPznWFP6uXnX7gKxyJT9//cYVxTO6+b1TT13Yvrpm1a4EuCOhLrZH6ErHQTccAM\nhAx8mdNtbROsp0dlPKrSfqO82uFz45RXZYmSeP0CAwEAAaM4MDYwDAYDVR0TAQH/\nBAIwADAOBgNVHQ8BAf8EBAMCB4AwFgYDVR0lAQH/BAwwCgYIKwYBBQUHAwIwDQYJ\nKoZIhvcNAQEFBQADggEBACNsJ5m00gdTvD6j6ahURsGrNZ0VJ0YREVQ5U2Jtubr8\nn2fuhMxkB8147ISzfi6wZR+yNwPGjlr8JkAHAC0i+Nam9SqRyfZLqsm+tHdgFT8h\npa+R/FoGrrLzxJNRiv0Trip8hZjgz3PClz6KxBQzqL+rfGV2MbwTXuBoEvLU1mYA\no3/UboJT7cNGjZ8nHXeoKMsec1/H55lUdconbTm5iMU1sTDf+3StGYzTwC+H6yc2\nY3zIq3/cQUCrETkALrqzyCnLjRrLYZu36ITOaKUbtmZhwrP99i2f+H4Ab2i8jeMu\nk61HD29mROYjl95Mko2BxL+76To7+pmn73U9auT+xfA=\n-----END CERTIFICATE-----\n",
787+
'cors.allowedOrigins' => '*',
788+
'cors.allowHeaders' => 'X-Authorization'
789+
```
790+
791+
Notes:
792+
- The `kid:key` pair is formatted as a string
793+
- Do not include spaces before or after the ':'
794+
- Use double quotation marks (") around the string text
795+
- The string must contain the linefeeds (\n)
764796

765797
To test your integration, you can copy the [firebase/vanilla.html](examples/clients/firebase/vanilla.html)
766798
file and the [firebase/vanilla-success.html](examples/clients/firebase/vanilla-success.html) file,

0 commit comments

Comments
 (0)