|
1 |
| -ELECTION APP |
2 |
| -=========== |
3 |
| -Election App |
| 1 | +# Padlock, Phalcon Authentication Server |
4 | 2 |
|
5 |
| -Features |
6 |
| --------- |
7 |
| -* ... |
| 3 | +[![Latest Version on Packagist][ico-version]][link-packagist] |
| 4 | +[![Software License][ico-license]](LICENSE.md) |
| 5 | +[![Total Downloads][ico-downloads]][link-downloads] |
8 | 6 |
|
| 7 | +Padlock is a docker-based phalcon authentication server built on top of the [PHP OAuth 2.0 Server](https://github.com/thephpleague/oauth2-server) |
9 | 8 |
|
10 |
| -Contributors |
| 9 | +Setting Up |
11 | 10 | ------------
|
12 |
| -* Tega Oghenekohwo <[email protected]> |
| 11 | +* Add the entries `padlock.local` and `padlock-test.local` and map to `127.0.0.1` in your `/etc/hosts` file |
13 | 12 |
|
| 13 | +* Ensure you have docker installed |
14 | 14 |
|
15 |
| -Requirements |
16 |
| ------------- |
17 |
| -* [Phalcon 3.3](https://docs.phalconphp.com/en/latest/reference/install.html) |
18 |
| -* [Composer](https://getcomposer.org/doc/00-intro.md#using-composer) |
| 15 | +* Make a copy of `.env.sample` to `.env` in the `app/env/` directory and replace the values. |
| 16 | + |
| 17 | +* You can generate the `ENCRYPTION_KEY` environment variable by running |
| 18 | +`php -r "echo base64_encode(random_bytes(40)) . PHP_EOL;"` on the command line |
| 19 | + |
| 20 | +* cd into the `keys` directory and generate your public and private keys like so: `openssl genrsa -out private.key 2048` |
| 21 | +then `openssl rsa -in private.key -pubout -out public.key`. These are needed for encrypting and decrypting tokens |
| 22 | + |
| 23 | +* Feel free to change the port mappings in `docker-compose.yml` if you already have services running on ports `8899` for |
| 24 | +the phalcon app and `33066` for the mysql server |
| 25 | + |
| 26 | +* Run the app like this `./bin/start.sh` or run `docker-compose up -d` |
| 27 | + |
| 28 | +* Login to mysql using the credentials host:127.0.0.1, username: root, password:root, port: 33066 |
| 29 | + |
| 30 | +* Create two databases: `padlock_db` and `padlock_test_db` and import the sql file found in `app/db/padlock.sql` into |
| 31 | +both databases |
| 32 | + |
| 33 | +Try it out |
| 34 | +========== |
| 35 | + |
| 36 | +Requesting a Token |
| 37 | +------------------ |
| 38 | + |
| 39 | +1. Password Grant Flow: Send a `POST` request to `http://padlock.local/api/v1/oauth/token` with the following parameters: |
| 40 | + - client_id: test |
| 41 | + - client_secret: secret |
| 42 | + - grant_type: password |
| 43 | + - username: abc |
| 44 | + - password: abc |
| 45 | + |
| 46 | + NOTE: This grant returns an access token and a refresh token |
| 47 | + |
| 48 | +2. Client Credentials Grant Flow: Send a `POST` request to `http://padlock.local/api/v1/oauth/token` with the following parameters: |
| 49 | + - client_id: test |
| 50 | + - client_secret: secret |
| 51 | + - grant_type: client_credentials |
| 52 | + |
| 53 | + NOTE: This grant returns only an access token |
| 54 | + |
| 55 | +3. Refresh Token Grant: Send a `POST` request to `http://padlock.local/api/v1/oauth/token` with the following parameters: |
| 56 | + - client_id: test |
| 57 | + - client_secret: secret |
| 58 | + - grant_type: refresh_token |
| 59 | + - refresh_token: value gotten from any flow that returns a refresh token (e.g password grant flow) |
| 60 | + |
| 61 | + NOTE: This grant returns another access token and refresh token and invalidates/revokes the previous ones |
| 62 | + |
| 63 | +4. Implicit Grant: Send a `GET` request to `http://padlock.local/api/v1/oauth/authorize` with the following parameters: |
| 64 | + - client_id: test |
| 65 | + - response_type: token |
| 66 | + - state: a random string (optional) |
| 67 | + - redirect_uri: http://www.test.com (optional) |
| 68 | + |
| 69 | + NOTE: This grant returns an access token immediately. It does not return a refresh token. |
| 70 | + |
| 71 | +5. Authorization Code Grant: Send a `GET` request to `http://padlock.local/api/v1/oauth/authorize` with the following parameters: |
| 72 | + - client_id: test |
| 73 | + - response_type: code |
| 74 | + - state: a random string (optional) |
| 75 | + - redirect_uri: http://www.test.com (optional) |
| 76 | + |
| 77 | + NOTE: This grant returns an authorization code that is then used to request for a token by sending a `POST` |
| 78 | + request to the endpoint `http://padlock.local/api/v1/oauth/token` with the following parameters: |
| 79 | + - client_id: test |
| 80 | + - client_secret: secret |
| 81 | + - grant_type: authorization_code |
| 82 | + - code: value gotten from the get request |
| 83 | + - redirect_uri: http://www.test.com (optional) |
| 84 | + |
| 85 | +Validating a Token |
| 86 | +------------------ |
| 87 | +Send a `POST` request to `http://padlock.local/api/v1/oauth/token/validate` with an `Authorization` header whose value is |
| 88 | +`Bearer {access_token}` |
| 89 | + |
19 | 90 |
|
| 91 | +Running Tests |
| 92 | +------------- |
20 | 93 |
|
21 |
| -Installation |
22 |
| ------------- |
| 94 | +* Make a copy of `.env.sample` to `.env.test` in the `app/env/` directory and replace the values. |
23 | 95 |
|
24 |
| -Setup Environment Variables |
25 |
| ---------------------------- |
26 |
| -Make a copy of .env.sample to .env in the env directory and replace the values. |
| 96 | +* Login to the app container using `./bin/login.sh` or run `docker exec -it padlock_app bash` |
27 | 97 |
|
| 98 | +* Execute unit tests `./unit-test.sh` (uses [PHPUnit](https://phpunit.de/)) |
28 | 99 |
|
29 |
| -Set Up Using Docker |
30 |
| -------------------------------- |
| 100 | +* Run integration tests using `./integration-test.sh` (uses [Codeception](https://codeception.com/)) |
31 | 101 |
|
32 |
| -* `php vendor/bin/phinx migrate` |
| 102 | +## Install |
33 | 103 |
|
34 |
| -* Ensure you have docker installed |
| 104 | +Via Composer |
35 | 105 |
|
36 |
| -* Create a clone of the `.env.testing.sample` file and name it `.env` and replace the values of the variables |
| 106 | +``` bash |
| 107 | +$ composer require tegaphilip/padlock |
| 108 | +``` |
37 | 109 |
|
38 |
| -* Login to mysql using the credentials host:127.0.0.1, username: root, password:root, port: 32800 |
| 110 | +## Change log |
39 | 111 |
|
40 |
| -* Create two databases: `election_app` and `election_app_test` |
| 112 | +Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently. |
41 | 113 |
|
42 |
| -* Run migrations `php vendor/bin/phinx migrate` |
43 | 114 |
|
44 |
| -Run the following to import states, etc from Excel File (If any of the scripts fail, try without the underscore) |
| 115 | +## Contributing |
45 | 116 |
|
46 |
| -* `DB_HOST=mysql DB_USER=root DB_PASSWORD=root DB_NAME=election_app php app/cli.php states_import import` |
47 |
| -* `DB_HOST=mysql DB_USER=root DB_PASSWORD=root DB_NAME=election_app php app/cli.php lgas_import import` |
48 |
| -* `DB_HOST=mysql DB_USER=root DB_PASSWORD=root DB_NAME=election_app php app/cli.php wards_import import` |
49 |
| -* `DB_HOST=mysql DB_USER=root DB_PASSWORD=root DB_NAME=election_app php app/cli.php stations_import import` |
50 |
| -* `DB_HOST=mysql DB_USER=root DB_PASSWORD=root DB_NAME=election_app php app/cli.php inec_lgas_import import` |
51 |
| -* `DB_HOST=mysql DB_USER=root DB_PASSWORD=root DB_NAME=election_app php app/cli.php inec_wards_import import` |
52 |
| -* `DB_HOST=mysql DB_USER=root DB_PASSWORD=root DB_NAME=election_app php app/cli.php inec_stations_import import` |
| 117 | +Please see [CONTRIBUTING](CONTRIBUTING.md) and [CONDUCT](CONDUCT.md) for details. |
53 | 118 |
|
54 |
| -Running Tests |
55 |
| -------------- |
| 119 | +## Security |
| 120 | + |
| 121 | +If you discover any security related issues, please email <[email protected]> instead of using the issue tracker. |
| 122 | + |
| 123 | +## Credits |
| 124 | + |
| 125 | +- [Tega Oghenekohwo](https://github.com/tegaphilip) |
| 126 | +- [Adeyemi Olaoye](https://github.com/yemexx1) |
| 127 | +- [All Contributors][link-contributors] |
| 128 | + |
| 129 | + |
| 130 | +[ico-version]: https://img.shields.io/packagist/v/tegaphilip/padlock.svg?style=flat-square |
| 131 | +[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square |
| 132 | +[ico-downloads]: https://img.shields.io/packagist/dt/tegaphilip/padlock.svg?style=flat-square |
| 133 | + |
| 134 | +[link-packagist]: https://packagist.org/packages/tegaphilip/padlock |
| 135 | +[link-code-quality]: https://scrutinizer-ci.com/g/tegaphilip/padlock |
| 136 | +[link-downloads]: https://packagist.org/packages/tegaphilip/padlock |
| 137 | +[link-contributors]: ../../contributors |
56 | 138 |
|
57 |
| -Create a clone of the `.env.testing.sample` file and name it `.env.testing` and replace the values of the variables |
58 |
| - |
59 |
| -* Create a test database `election_app_test` |
60 |
| - |
61 |
| -* Execute tests using `./runtest.sh` to run all tests or `./runtest.sh {testName}` to run a particular test. E.g `./runtest.sh UserCest` |
62 |
| - |
63 |
| -php vendor/bin/phinx create StateMigration |
64 |
| - |
65 |
| -Deploying on Staging |
66 |
| --------------------- |
67 |
| -* sudo apt-get update |
68 |
| -* Install apache with `sudo apt-get install apache2` |
69 |
| -* Get phalcon repository with `curl -s https://packagecloud.io/install/repositories/phalcon/stable/script.deb.sh | sudo bash` |
70 |
| -* Install phalcon with `sudo apt-get install php7.0-phalcon` |
71 |
| -* Check Phalcon Version with `php -r "echo Phalcon\Version::get();"` |
72 |
| -* sudo apt-get install php7.0-mbstring |
73 |
| -* sudo apt-get install php7.0-curl |
74 |
| -* sudo apt-get install php7.0-xml |
75 |
| -* sudo apt-get install php7.0-mysql |
76 |
| -* sudo apt-get install php7.1-phalcon |
77 |
| -* https://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu-16-04 |
78 |
| -* https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-in-ubuntu-16-04 |
79 |
| -* extensions /usr/lib/php/20160303 |
80 |
| -* INI APACHE cat /etc/php/7.1/apache2/php.ini |
81 |
| -* ADDITIONAL INI APACHE ls -al /etc/php/7.1/apache2/conf.d |
82 |
| -* INI CLI cat /etc/php/7.1/cli/php.ini |
83 |
| -* ADDITIONAL INI CLI ls -al /etc/php/7.1/cli/conf.d |
84 |
| -* sudo find / -iname 'phalcon.so' -exec rm -f {} \; // remove |
85 |
| -* sudo find / -iname 'phalcon.so' |
86 |
| - |
87 |
| -sudo apt-get install -y php7.1 libapache2-mod-php7.1 php7.1-cli php7.1-common php7.1-mbstring php7.1-gd php7.1-intl php7.1-xml php7.1-mysql php7.1-mcrypt php7.1-zip |
88 |
| -sudo apt-get install -y php7.1-curl |
89 |
| - |
90 |
| -* For some reason addExistence Validation causes things to fail on staging server (AWS, DO, etc) |
91 |
| - |
92 |
| -* Run import tasks |
93 | 139 |
|
94 | 140 |
|
0 commit comments