forked from harmen/mjsapi
No description
| .gitignore | ||
| .htaccess | ||
| base32.php | ||
| config.template | ||
| index.php | ||
| README.md | ||
| template.sql | ||
| ttn.php | ||
| users.php | ||
MJSAPI
Dependencies
- Apache2 with PHP, htaccess and mod_rewrite. Another webserver with
PHP support can work, but then the redirects in
.htaccessmight need to be ported to it. - PHP module: sqlite3
On Debian, this can be achieved with;
apt install apache2 libapache2-mod-php php-sqlite3
sudo a2enmod rewrite
sudo tee /etc/apache2/conf-enabled/local-allow-htaccess-rewrite.conf <<EOF
<Directory /var/www/>
AllowOverride FileInfo AuthConfig Limit Indexes
</Directory>
EOF
sudo systemctl restart apache2
Setup
-
Clone git repository inside the Apache documentroot and make the directory writable by PHP. E.g.:
sudo mkdir /var/www/html/mjsapi sudo chown "$USER" /var/www/html/mjsapi git clone https://src.giplt.nl/harmen/mjsapi.git /var/www/html/mjsapi sudo chown "www-data" /var/www/html/mjsapiThis first creates the directory writable to your current user (so you do not need to run git as sudo), and then changes the directory ownership to allow PHP to create the database.
-
Copy
config.templatetoconfig.jsonand fill in config values:systemEmailNameandsystemEmailAddress: Used as the sender of outgoing e-mails.sqliteUserDatabase: Path to the database file. It will be created and filled when it does not exist yet.JWT_KEY: This must be a random value with at least 256 bits (matching the HS256 algorithm used) of randomness (32 bytes). It can be a raw binary value, ASCII string or hex string. For example, generate with:openssl rand -hex 32.
Register user manually
-
Register account:
API=http://localhost/mjsapi curl -i -d '{"email": "email@example.org", "password1": "foo", "password2": "foo", "display_name": "My Name"}' -X POST "$API/users/register" -
Click link in confirmation e-mail.
-
Login:
curl -i -d '{"email": "email@example.org", "password": "foo"}' -X POST "$API/users/authenticate" -
Extract the JWT from the response and use that to authenticate further requests (e.g.):
JWT=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6MSwiZGlzcGxheV9uYW1lIjoiTXkgTmFtZSIsImVtYWlsIjoibWF0dGhpanNAc3RkaW4ubmwiLCJhZG1pbiI6MSwiaWF0IjoxNzM0NDU0MTA2fQ==.MTU5ODQ1NmQ2MGFjMTFkNTEwY2EwODU5YmRlNzhhZmVkZTM4ZTg1YzMwMjRlNDFjMjlkNGJkOWNiNDU3MTMxMw== curl -i -H "Authorization: JWT $JWT" -X GET "$API/users"