├── CONTRIBUTING.md ├── LICENSE ├── README.md └── composer.json /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ### Please ;) ... 2 | 3 | 1. Create pull requests from specific branches, not `master`. 4 | 5 | 2. Write goo commit messages (if you use Github embedded editor for committing, the default commit message offered to you is ussually not good enough). You may get inspired in [Pre-emptive commit comments](http://arialdomartini.wordpress.com/2012/09/03/pre-emptive-commit-comments/) [EN] or [Commitujte jako profík!](http://www.zdrojak.cz/clanky/commitujte-jako-profik/) [CZ]. 6 | 7 | 3. Use English and keep coding style. 8 | 9 | ### Thanks for contribution! 10 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014, Vojtěch Dobeš 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | * Neither the name of the VojtechDobes\MultiAuthenticator nor the names of its 15 | contributors may be used to endorse or promote products derived from 16 | this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 22 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## For Nette Framework 2 | 3 | Allows definition of multiple authentication ways with unified API (for Nette Framework) 4 | 5 | ##### License 6 | 7 | [New BSD](http://choosealicense.com/licenses/bsd-3-clause/) 8 | 9 | ##### Dependencies 10 | 11 | Nette 2.0 or newer 12 | 13 | ## Installation 14 | 15 | None, really :). 16 | 17 | ## Usage 18 | 19 | Write your authenticators, but don't make them implement `Nette\Security\IAuthenticator`. On the other hand, request `Nette\Security\User` service as dependency. 20 | 21 | ```php 22 | class CredentialsAuthenticator 23 | { 24 | 25 | /** @var Nette\Security\User */ 26 | private $user; 27 | 28 | public function __construct(Nette\Security\User $user) 29 | { 30 | $this->user = $user; 31 | } 32 | 33 | } 34 | ``` 35 | 36 | Now write your login method. Be creative! 37 | 38 | ```php 39 | public function login($username, $password) 40 | { 41 | // ... your logic 42 | 43 | $this->user->login(new Identity( ... )); 44 | } 45 | ``` 46 | 47 | Register your authenticator as service: 48 | 49 | ```neon 50 | services: 51 | - CredentialsAuthenticator 52 | ``` 53 | 54 | And you're done. 55 | 56 | For authentication, you should use the specific authenticator: 57 | 58 | ```php 59 | class SignPresenter extends Nette\Application\UI\Presenter 60 | { 61 | 62 | /** @var CredentialsAuthenticator @inject */ 63 | public $credentialsAuthenticator; 64 | 65 | // ... 66 | 67 | public function processLoginForm($form) 68 | { 69 | $values = $form->getValues(); 70 | $this->credentialsAuthenticator->login($values->username, $values->password); 71 | } 72 | 73 | } 74 | ``` 75 | 76 | The point is: use normal dependencies and wrap `Nette\Security\User` in them, not the other way around. 77 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vojtech-dobes/nette-multi-authenticator", 3 | "description": "Allows definition of multiple authentication ways with unified API (for Nette Framework).", 4 | "keywords": ["nette", "security", "authentication"], 5 | "homepage": "http://github.com/vojtech-dobes/nette-multi-authenticator", 6 | "license": "New BSD", 7 | "authors": [ 8 | { 9 | "name": "Vojtěch Dobeš", 10 | "email": "me@vojtechdobes.com" 11 | } 12 | ], 13 | "require": { 14 | "php": ">=5.3.2", 15 | "nette/nette": "~2.0" 16 | }, 17 | "autoload": { 18 | "classmap": ["."] 19 | } 20 | } 21 | --------------------------------------------------------------------------------