├── .gitignore ├── LICENSE.md ├── README.md ├── assets └── AppAsset.php ├── codeception.yml ├── composer.json ├── config ├── params.php └── web.php ├── controllers └── SiteController.php ├── models ├── LoginForm.php └── User.php ├── requirements.php ├── runtime └── .gitignore ├── views ├── layouts │ └── main.php └── site │ ├── error.php │ ├── index.php │ └── login.php ├── web ├── .htaccess ├── assets │ └── .gitignore ├── css │ └── site.css └── index.php ├── yii └── yii.bat /.gitignore: -------------------------------------------------------------------------------- 1 | /composer.lock 2 | /composer-local.json 3 | /vendor* 4 | .idea 5 | /config/web-local.php 6 | /views/layouts/_main_analytics.php -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The Yii framework is free software. It is released under the terms of 2 | the following BSD License. 3 | 4 | Copyright © 2008-2013 by Yii Software LLC (http://www.yiisoft.com) 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | * Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | * Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | * Neither the name of Yii Software LLC nor the names of its 18 | contributors may be used to endorse or promote products derived 19 | from this software without specific prior written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 24 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 25 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 26 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 27 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 31 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Yii2 EAuth demo project 2 | ======================= 3 | 4 | EAuth extension allows to authenticate users with accounts on other websites. 5 | Supported protocols: OpenID, OAuth 1.0 and OAuth 2.0. 6 | 7 | EAuth is a extension for provide a unified (does not depend on the selected service) method to authenticate the user. So, the extension itself does not perform login, does not register the user and does not bind the user accounts from different providers. 8 | 9 | * [Online Demo](http://nodge.ru/yii-eauth/demo2/) 10 | * [Extension project](https://github.com/Nodge/yii2-eauth/) 11 | * [Version for yii 1.1](https://github.com/Nodge/yii-eauth-demo/) 12 | 13 | 14 | ## Extension 15 | 16 | For more details see [yii2-eauth](https://github.com/Nodge/yii2-eauth) project. 17 | 18 | 19 | ## License 20 | 21 | The extension was released under the [New BSD License](http://www.opensource.org/licenses/bsd-license.php), so you'll find the latest version on [GitHub](https://github.com/Nodge/yii2-eauth-demo). -------------------------------------------------------------------------------- /assets/AppAsset.php: -------------------------------------------------------------------------------- 1 | 14 | * @since 2.0 15 | */ 16 | class AppAsset extends AssetBundle 17 | { 18 | public $basePath = '@webroot'; 19 | public $baseUrl = '@web'; 20 | public $css = array( 21 | 'css/site.css', 22 | ); 23 | public $js = array( 24 | ); 25 | public $depends = array( 26 | 'yii\web\YiiAsset', 27 | 'yii\bootstrap\BootstrapAsset', 28 | ); 29 | } 30 | -------------------------------------------------------------------------------- /codeception.yml: -------------------------------------------------------------------------------- 1 | paths: 2 | tests: tests 3 | log: tests/_log 4 | data: tests/_data 5 | helpers: tests/_helpers 6 | settings: 7 | bootstrap: _bootstrap.php 8 | suite_class: \PHPUnit_Framework_TestSuite 9 | colors: true 10 | memory_limit: 1024M 11 | log: true 12 | modules: 13 | config: 14 | Db: 15 | dsn: '' 16 | user: '' 17 | password: '' 18 | dump: tests/_data/dump.sql 19 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nodge/yii2-eauth-demo", 3 | "description": "Demo site for Yii 2 EAuth extension", 4 | "keywords": ["yii", "framework", "demo", "eauth"], 5 | "homepage": "https://github.com/Nodge/yii2-eauth", 6 | "type": "project", 7 | "license": "New BSD License", 8 | "authors": [ 9 | { 10 | "name": "Maxim Zemskov", 11 | "email": "nodge@yandex.ru", 12 | "homepage": "http://nodge.ru/" 13 | } 14 | ], 15 | "minimum-stability": "dev", 16 | "require": { 17 | "php": ">=5.4.0", 18 | "yiisoft/yii2": "*", 19 | "yiisoft/yii2-bootstrap": "*", 20 | "yiisoft/yii2-debug": "*", 21 | "yiisoft/yii2-gii": "*", 22 | "nodge/yii2-eauth": "*" 23 | }, 24 | "scripts": { 25 | "post-create-project-cmd": [ 26 | "yii\\composer\\InstallHandler::setPermissions" 27 | ] 28 | }, 29 | "extra": { 30 | "writable": [ 31 | "runtime", 32 | "web/assets" 33 | ], 34 | "executable": [ 35 | "yii" 36 | ] 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /config/params.php: -------------------------------------------------------------------------------- 1 | 'admin@example.com', 5 | ); 6 | -------------------------------------------------------------------------------- /config/web.php: -------------------------------------------------------------------------------- 1 | 'bootstrap', 5 | 'name' => 'Yii2 EAuth extension demo', 6 | 'basePath' => dirname(__DIR__), 7 | 'extensions' => require(__DIR__ . '/../vendor/yiisoft/extensions.php'), 8 | 'components' => array( 9 | 'cache' => array( 10 | 'class' => 'yii\caching\FileCache', 11 | ), 12 | 'user' => array( 13 | 'identityClass' => 'app\models\User', 14 | ), 15 | 'errorHandler' => array( 16 | 'errorAction' => 'site/error', 17 | ), 18 | 'i18n' => array( 19 | 'translations' => array( 20 | 'eauth' => array( 21 | 'class' => 'yii\i18n\PhpMessageSource', 22 | 'basePath' => '@eauth/messages', 23 | ), 24 | ), 25 | ), 26 | 'eauth' => array( 27 | 'class' => 'nodge\eauth\EAuth', 28 | 'popup' => true, // Use the popup window instead of redirecting. 29 | 'cache' => false, // Cache component name or false to disable cache. Defaults to 'cache' on production environments. 30 | 'cacheExpire' => 0, // Cache lifetime. Defaults to 0 - means unlimited. 31 | // 'httpClient' => array( 32 | // uncomment this to use streams in safe_mode 33 | //'useStreamsFallback' => true, 34 | // ), 35 | // 'tokenStorage' => array( 36 | // 'class' => '@app\eauth\DatabaseTokenStorage', 37 | // ), 38 | 'services' => array( 39 | 'google_oauth' => array( 40 | // register your app here: https://code.google.com/apis/console/ 41 | 'class' => 'nodge\eauth\services\GoogleOAuth2Service', 42 | 'clientId' => '...', 43 | 'clientSecret' => '...', 44 | 'title' => 'Google', 45 | ), 46 | 'facebook' => array( 47 | // register your app here: https://developers.facebook.com/apps/ 48 | 'class' => 'nodge\eauth\services\FacebookOAuth2Service', 49 | 'clientId' => '...', 50 | 'clientSecret' => '...', 51 | ), 52 | 'twitter' => array( 53 | // register your app here: https://dev.twitter.com/apps/new 54 | 'class' => 'nodge\eauth\services\TwitterOAuth1Service', 55 | 'key' => '...', 56 | 'secret' => '...', 57 | ), 58 | 'yahoo' => array( 59 | 'class' => 'nodge\eauth\services\YahooOpenIDService', 60 | ), 61 | 'linkedin' => array( 62 | // register your app here: https://www.linkedin.com/secure/developer 63 | 'class' => 'nodge\eauth\services\LinkedinOAuth1Service', 64 | 'key' => '...', 65 | 'secret' => '...', 66 | 'title' => 'LinkedIn (OAuth1)', 67 | ), 68 | 'linkedin_oauth2' => array( 69 | // register your app here: https://www.linkedin.com/secure/developer 70 | 'class' => 'nodge\eauth\services\LinkedinOAuth2Service', 71 | 'clientId' => '...', 72 | 'clientSecret' => '...', 73 | 'title' => 'LinkedIn (OAuth2)', 74 | ), 75 | 'github' => array( 76 | // register your app here: https://github.com/settings/applications 77 | 'class' => 'nodge\eauth\services\GitHubOAuth2Service', 78 | 'clientId' => '...', 79 | 'clientSecret' => '...', 80 | ), 81 | 'live' => array( 82 | // register your app here: https://account.live.com/developers/applications/index 83 | 'class' => 'nodge\eauth\services\LiveOAuth2Service', 84 | 'clientId' => '...', 85 | 'clientSecret' => '...', 86 | ), 87 | 'steam' => array( 88 | 'class' => 'nodge\eauth\services\SteamOpenIDService', 89 | ), 90 | 'yandex_oauth' => array( 91 | // register your app here: https://oauth.yandex.ru/client/my 92 | 'class' => 'nodge\eauth\services\YandexOAuth2Service', 93 | 'clientId' => '...', 94 | 'clientSecret' => '...', 95 | 'title' => 'Yandex', 96 | ), 97 | 'vkontakte' => array( 98 | // register your app here: https://vk.com/editapp?act=create&site=1 99 | 'class' => 'nodge\eauth\services\VKontakteOAuth2Service', 100 | 'clientId' => '...', 101 | 'clientSecret' => '...', 102 | ), 103 | 'mailru' => array( 104 | // register your app here: http://api.mail.ru/sites/my/add 105 | 'class' => 'nodge\eauth\services\MailruOAuth2Service', 106 | 'clientId' => '...', 107 | 'clientSecret' => '...', 108 | ), 109 | 'odnoklassniki' => array( 110 | // register your app here: http://dev.odnoklassniki.ru/wiki/pages/viewpage.action?pageId=13992188 111 | // ... or here: http://www.odnoklassniki.ru/dk?st.cmd=appsInfoMyDevList&st._aid=Apps_Info_MyDev 112 | 'class' => 'nodge\eauth\services\OdnoklassnikiOAuth2Service', 113 | 'clientId' => '...', 114 | 'clientSecret' => '...', 115 | 'clientPublic' => '...', 116 | 'title' => 'Odnoklas.', 117 | ), 118 | ), 119 | ), 120 | 121 | // (optionally) you can configure pretty urls 122 | 'urlManager' => array( 123 | 'enablePrettyUrl' => true, 124 | 'showScriptName' => false, 125 | 'rules' => array( 126 | '' => 'site/index', 127 | 'login' => 'site/login', 128 | 'logout' => 'site/logout', 129 | ), 130 | ), 131 | 132 | // (optionally) you can configure logging 133 | 'log' => array( 134 | 'traceLevel' => YII_DEBUG ? 3 : 0, 135 | 'targets' => array( 136 | array( 137 | 'class' => 'yii\log\FileTarget', 138 | 'levels' => array('error', 'warning'), 139 | ), 140 | array( 141 | 'class' => 'yii\log\FileTarget', 142 | 'logFile' => '@app/runtime/logs/eauth.log', 143 | 'categories' => array('nodge\eauth\*'), 144 | 'logVars' => array(), 145 | ), 146 | ), 147 | ), 148 | ), 149 | 'params' => require(__DIR__ . '/params.php'), 150 | ); 151 | 152 | if (file_exists(__DIR__.'/web-local.php')) { 153 | $localConfig = require 'web-local.php'; 154 | $config = \yii\helpers\ArrayHelper::merge($config, $localConfig); 155 | } 156 | 157 | $eauthServices = array_keys($config['components']['eauth']['services']); 158 | array_unshift($config['components']['urlManager']['rules'], array( 159 | 'route' => 'site/login', 160 | 'pattern' => 'login/', 161 | )); 162 | 163 | return $config; -------------------------------------------------------------------------------- /controllers/SiteController.php: -------------------------------------------------------------------------------- 1 | array( 17 | 'class' => 'yii\web\ErrorAction', 18 | ), 19 | ); 20 | } 21 | 22 | public function behaviors() { 23 | return array( 24 | 'access' => array( 25 | 'class' => AccessControl::className(), 26 | 'only' => array('login'), 27 | 'rules' => array( 28 | array( 29 | 'allow' => true, 30 | // 'roles' => array('?'), 31 | ), 32 | array( 33 | 'allow' => false, 34 | 'denyCallback' => array($this, 'goHome'), 35 | ), 36 | ), 37 | ), 38 | 'eauth' => array( 39 | // required to disable csrf validation on OpenID requests 40 | 'class' => \nodge\eauth\openid\ControllerBehavior::className(), 41 | 'only' => array('login'), 42 | ), 43 | ); 44 | } 45 | 46 | public function actionIndex() 47 | { 48 | return $this->render('index'); 49 | } 50 | 51 | public function actionLogin() 52 | { 53 | $serviceName = Yii::$app->getRequest()->getQueryParam('service'); 54 | if (isset($serviceName)) { 55 | /** @var $eauth \nodge\eauth\ServiceBase */ 56 | $eauth = Yii::$app->get('eauth')->getIdentity($serviceName); 57 | $eauth->setRedirectUrl(Yii::$app->getUser()->getReturnUrl()); 58 | $eauth->setCancelUrl(Yii::$app->getUrlManager()->createAbsoluteUrl('site/login')); 59 | 60 | try { 61 | if ($eauth->authenticate()) { 62 | // var_dump($eauth->getIsAuthenticated(), $eauth->getAttributes()); exit; 63 | 64 | $identity = User::findByEAuth($eauth); 65 | Yii::$app->getUser()->login($identity); 66 | 67 | // special redirect with closing popup window 68 | $eauth->redirect(); 69 | } 70 | else { 71 | // close popup window and redirect to cancelUrl 72 | $eauth->cancel(); 73 | } 74 | } 75 | catch (\nodge\eauth\ErrorException $e) { 76 | // save error to show it later 77 | Yii::$app->getSession()->setFlash('error', 'EAuthException: '.$e->getMessage()); 78 | 79 | // close popup window and redirect to cancelUrl 80 | // $eauth->cancel(); 81 | $eauth->redirect($eauth->getCancelUrl()); 82 | } 83 | } 84 | 85 | $model = new LoginForm(); 86 | if ($model->load($_POST) && $model->login()) { 87 | return $this->goBack(); 88 | } 89 | else { 90 | return $this->render('login', array( 91 | 'model' => $model, 92 | )); 93 | } 94 | } 95 | 96 | public function actionLogout() 97 | { 98 | Yii::$app->user->logout(); 99 | return $this->goHome(); 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /models/LoginForm.php: -------------------------------------------------------------------------------- 1 | getUser(); 41 | if (!$user || !$user->validatePassword($this->password)) { 42 | $this->addError('password', 'Incorrect username or password.'); 43 | } 44 | } 45 | 46 | /** 47 | * Logs in a user using the provided username and password. 48 | * @return boolean whether the user is logged in successfully 49 | */ 50 | public function login() 51 | { 52 | if ($this->validate()) { 53 | return Yii::$app->user->login($this->getUser(), $this->rememberMe ? 3600*24*30 : 0); 54 | } else { 55 | return false; 56 | } 57 | } 58 | 59 | /** 60 | * Finds user by [[username]] 61 | * 62 | * @return User|null 63 | */ 64 | private function getUser() 65 | { 66 | if ($this->_user === false) { 67 | $this->_user = User::findByUsername($this->username); 68 | } 69 | return $this->_user; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /models/User.php: -------------------------------------------------------------------------------- 1 | array( 23 | 'id' => '100', 24 | 'username' => 'admin', 25 | 'password' => 'admin', 26 | 'authKey' => 'test100key', 27 | ), 28 | '101' => array( 29 | 'id' => '101', 30 | 'username' => 'demo', 31 | 'password' => 'demo', 32 | 'authKey' => 'test101key', 33 | ), 34 | ); 35 | 36 | public static function findIdentity($id) 37 | { 38 | if (Yii::$app->getSession()->has('user-'.$id)) { 39 | return new self(Yii::$app->getSession()->get('user-'.$id)); 40 | } 41 | else { 42 | return isset(self::$users[$id]) ? new self(self::$users[$id]) : null; 43 | } 44 | } 45 | 46 | public static function findByUsername($username) 47 | { 48 | foreach (self::$users as $user) { 49 | if (strcasecmp($user['username'], $username) === 0) { 50 | return new self($user); 51 | } 52 | } 53 | return null; 54 | } 55 | 56 | /** 57 | * @param \nodge\eauth\ServiceBase $service 58 | * @return User 59 | * @throws ErrorException 60 | */ 61 | public static function findByEAuth($service) { 62 | if (!$service->getIsAuthenticated()) { 63 | throw new ErrorException('EAuth user should be authenticated before creating identity.'); 64 | } 65 | 66 | $id = $service->getServiceName().'-'.$service->getId(); 67 | $attributes = array( 68 | 'id' => $id, 69 | 'username' => $service->getAttribute('name'), 70 | 'authKey' => md5($id), 71 | 'profile' => $service->getAttributes(), 72 | ); 73 | $attributes['profile']['service'] = $service->getServiceName(); 74 | Yii::$app->getSession()->set('user-'.$id, $attributes); 75 | return new self($attributes); 76 | } 77 | 78 | public function getId() { 79 | return $this->id; 80 | } 81 | 82 | public function getAuthKey() { 83 | return $this->authKey; 84 | } 85 | 86 | public function validateAuthKey($authKey) { 87 | return $this->authKey === $authKey; 88 | } 89 | 90 | public function validatePassword($password) { 91 | return $this->password === $password; 92 | } 93 | 94 | /** 95 | * Finds an identity by the given secrete token. 96 | * 97 | * @param string $token the secrete token 98 | * @param null $type type of $token 99 | * @return IdentityInterface the identity object that matches the given token. 100 | * Null should be returned if such an identity cannot be found 101 | * or the identity is not in an active state (disabled, deleted, etc.) 102 | */ 103 | public static function findIdentityByAccessToken($token, $type = null) { 104 | // TODO: Implement findIdentityByAccessToken() method. 105 | return null; 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /requirements.php: -------------------------------------------------------------------------------- 1 | Error'; 18 | echo '

The path to yii framework seems to be incorrect.

'; 19 | echo '

You need to install Yii framework via composer or adjust the framework path in file ' . basename(__FILE__) .'.

'; 20 | echo '

Please refer to the README on how to install Yii.

'; 21 | } 22 | 23 | require_once($frameworkPath . '/requirements/YiiRequirementChecker.php'); 24 | $requirementsChecker = new YiiRequirementChecker(); 25 | 26 | /** 27 | * Adjust requirements according to your application specifics. 28 | */ 29 | $requirements = [ 30 | // Database : 31 | [ 32 | 'name' => 'PDO extension', 33 | 'mandatory' => true, 34 | 'condition' => extension_loaded('pdo'), 35 | 'by' => 'All DB-related classes', 36 | ], 37 | [ 38 | 'name' => 'PDO SQLite extension', 39 | 'mandatory' => false, 40 | 'condition' => extension_loaded('pdo_sqlite'), 41 | 'by' => 'All DB-related classes', 42 | 'memo' => 'Required for SQLite database.', 43 | ], 44 | [ 45 | 'name' => 'PDO MySQL extension', 46 | 'mandatory' => false, 47 | 'condition' => extension_loaded('pdo_mysql'), 48 | 'by' => 'All DB-related classes', 49 | 'memo' => 'Required for MySQL database.', 50 | ], 51 | [ 52 | 'name' => 'PDO PostgreSQL extension', 53 | 'mandatory' => false, 54 | 'condition' => extension_loaded('pdo_pgsql'), 55 | 'by' => 'All DB-related classes', 56 | 'memo' => 'Required for PostgreSQL database.', 57 | ], 58 | // Cache : 59 | [ 60 | 'name' => 'Memcache extension', 61 | 'mandatory' => false, 62 | 'condition' => extension_loaded('memcache') || extension_loaded('memcached'), 63 | 'by' => 'CMemCache', 64 | 'memo' => extension_loaded('memcached') ? 'To use memcached set CMemCache::useMemcached to true.' : '' 65 | ], 66 | [ 67 | 'name' => 'APC extension', 68 | 'mandatory' => false, 69 | 'condition' => extension_loaded('apc'), 70 | 'by' => 'CApcCache', 71 | ], 72 | // Additional PHP extensions : 73 | [ 74 | 'name' => 'Mcrypt extension', 75 | 'mandatory' => false, 76 | 'condition' => extension_loaded('mcrypt'), 77 | 'by' => 'CSecurityManager', 78 | 'memo' => 'Required by encrypt and decrypt methods.' 79 | ], 80 | // PHP ini : 81 | 'phpSafeMode' => [ 82 | 'name' => 'PHP safe mode', 83 | 'mandatory' => false, 84 | 'condition' => $requirementsChecker->checkPhpIniOff("safe_mode"), 85 | 'by' => 'File uploading and console command execution', 86 | 'memo' => '"safe_mode" should be disabled at php.ini', 87 | ], 88 | 'phpExposePhp' => [ 89 | 'name' => 'Expose PHP', 90 | 'mandatory' => false, 91 | 'condition' => $requirementsChecker->checkPhpIniOff("expose_php"), 92 | 'by' => 'Security reasons', 93 | 'memo' => '"expose_php" should be disabled at php.ini', 94 | ], 95 | 'phpAllowUrlInclude' => [ 96 | 'name' => 'PHP allow url include', 97 | 'mandatory' => false, 98 | 'condition' => $requirementsChecker->checkPhpIniOff("allow_url_include"), 99 | 'by' => 'Security reasons', 100 | 'memo' => '"allow_url_include" should be disabled at php.ini', 101 | ], 102 | 'phpSmtp' => [ 103 | 'name' => 'PHP mail SMTP', 104 | 'mandatory' => false, 105 | 'condition' => strlen(ini_get('SMTP'))>0, 106 | 'by' => 'Email sending', 107 | 'memo' => 'PHP mail SMTP server required', 108 | ], 109 | ]; 110 | $requirementsChecker->checkYii()->check($requirements)->render(); -------------------------------------------------------------------------------- /runtime/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore -------------------------------------------------------------------------------- /views/layouts/main.php: -------------------------------------------------------------------------------- 1 | 14 | beginPage(); ?> 15 | 16 | 17 | 18 | 19 | <?php echo Html::encode($this->title); ?> 20 | head(); ?> 21 | 22 | 23 | beginBody(); ?> 24 | 25 | 26 | Fork me on GitHub 27 | 28 | 29 | Yii::$app->name, 32 | 'brandUrl' => Yii::$app->homeUrl, 33 | 'options' => array( 34 | 'class' => 'navbar-inverse navbar-fixed-top', 35 | ), 36 | )); 37 | echo Nav::widget(array( 38 | 'options' => array('class' => 'navbar-nav pull-right'), 39 | 'items' => array( 40 | array('label' => 'Home', 'url' => array('/site/index')), 41 | Yii::$app->user->isGuest ? 42 | array('label' => 'Login', 'url' => array('/site/login')) : 43 | array('label' => 'Logout (' . Yii::$app->user->identity->username .')' , 'url' => array('/site/logout')), 44 | ), 45 | )); 46 | NavBar::end(); 47 | 48 | $identity = Yii::$app->getUser()->getIdentity(); 49 | if (isset($identity->profile)) { 50 | echo '
'; 51 | echo 'EAuth profile:
'; 52 | VarDumper::dump($identity->profile, 10, true); 53 | echo '
'; 54 | } 55 | ?> 56 | 57 |
58 | isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : array(), 60 | )); ?> 61 | 62 |
63 | 64 | 70 | 71 | 76 | 77 | endBody(); ?> 78 | 79 | 80 | endPage(); ?> 81 | -------------------------------------------------------------------------------- /views/site/error.php: -------------------------------------------------------------------------------- 1 | title = $name; 13 | ?> 14 |
15 | 16 |

title); ?>

17 | 18 |
19 | 20 |
21 | 22 |

23 | The above error occurred while the Web server was processing your request. 24 |

25 |

26 | Please contact us if you think this is a server error. Thank you. 27 |

28 | 29 |
-------------------------------------------------------------------------------- /views/site/index.php: -------------------------------------------------------------------------------- 1 | title = \Yii::$app->name; 10 | ?> 11 | 12 |
13 |

EAuth for Yii2

14 | 15 |

EAuth extension allows to authenticate users by the OpenID
and OAuth providers.

16 |

See page for demo.

17 |

For more details please visit our GitHub page.

18 | 19 | Get started with EAuth 20 |     21 | getUser()->isGuest) : ?> 22 | Login (demo) 23 | 24 | Logout 25 | 26 |
-------------------------------------------------------------------------------- /views/site/login.php: -------------------------------------------------------------------------------- 1 | title = 'Login'; 12 | $this->params['breadcrumbs'][] = $this->title; 13 | ?> 14 |

title); ?>

15 | 16 | getSession()->hasFlash('error')) { 18 | echo '
'.Yii::$app->getSession()->getFlash('error').'
'; 19 | } 20 | ?> 21 | 22 |

Do you already have an account on one of these sites? Click the logo to log in with it here:

23 | 'site/login')); ?> 24 |
25 | 26 |

Please fill out the following fields to login:

27 | 28 | array('class' => 'form-horizontal', 'id' => 'login-form'))); ?> 29 | field($model, 'username')->textInput(); ?> 30 | field($model, 'password')->passwordInput(); ?> 31 | field($model, 'rememberMe')->checkbox(); ?> 32 |
33 | 'btn btn-primary')); ?> 34 |
35 | 36 | -------------------------------------------------------------------------------- /web/.htaccess: -------------------------------------------------------------------------------- 1 | 2 | AddDefaultCharset UTF-8 3 | 4 | Options +FollowSymLinks 5 | IndexIgnore */* 6 | RewriteEngine on 7 | 8 | # if a directory or a file exists, use it directly 9 | RewriteCond %{REQUEST_FILENAME} !-f 10 | RewriteCond %{REQUEST_FILENAME} !-d 11 | 12 | # otherwise forward it to index.php 13 | RewriteRule . index.php -------------------------------------------------------------------------------- /web/assets/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore -------------------------------------------------------------------------------- /web/css/site.css: -------------------------------------------------------------------------------- 1 | body { 2 | padding-top: 60px; 3 | padding-bottom: 60px; 4 | } 5 | 6 | /* Custom container */ 7 | .container { 8 | margin: 0 auto; 9 | max-width: 1000px; 10 | } 11 | 12 | .container > hr { 13 | margin: 60px 0; 14 | } 15 | 16 | /* Main marketing message and sign up button */ 17 | .jumbotron { 18 | margin: 80px 0; 19 | text-align: center; 20 | } 21 | 22 | .jumbotron h1 { 23 | font-size: 100px; 24 | line-height: 1; 25 | } 26 | 27 | .jumbotron .lead { 28 | font-size: 24px; 29 | line-height: 1.25; 30 | } 31 | 32 | .jumbotron .btn { 33 | font-size: 21px; 34 | padding: 14px 24px; 35 | } 36 | 37 | /* Supporting marketing content */ 38 | .marketing { 39 | margin: 60px 0; 40 | } 41 | 42 | .marketing p + h4 { 43 | margin-top: 28px; 44 | } 45 | 46 | /* Customize the navbar links to be fill the entire space of the .navbar */ 47 | .navbar.fullwidth .navbar-inner { 48 | padding: 0; 49 | } 50 | 51 | .navbar.fullwidth .nav { 52 | margin: 0; 53 | display: table; 54 | width: 100%; 55 | } 56 | 57 | .navbar.fullwidth .nav li { 58 | display: table-cell; 59 | width: 1%; 60 | float: none; 61 | } 62 | 63 | .navbar.fullwidth .nav li a { 64 | font-weight: bold; 65 | text-align: center; 66 | border-left: 1px solid rgba(255, 255, 255, .75); 67 | border-right: 1px solid rgba(0, 0, 0, .1); 68 | } 69 | 70 | .navbar.fullwidth .nav li:first-child a { 71 | border-left: 0; 72 | border-radius: 3px 0 0 3px; 73 | } 74 | 75 | .navbar.fullwidth .nav li:last-child a { 76 | border-right: 0; 77 | border-radius: 0 3px 3px 0; 78 | } 79 | 80 | .eauth { 81 | margin: 10px 0; 82 | } -------------------------------------------------------------------------------- /web/index.php: -------------------------------------------------------------------------------- 1 | run(); 14 | -------------------------------------------------------------------------------- /yii: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env php 2 | run(); 23 | exit($exitCode); -------------------------------------------------------------------------------- /yii.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | rem ------------------------------------------------------------- 4 | rem Yii command line bootstrap script for Windows. 5 | rem 6 | rem @author Qiang Xue 7 | rem @link http://www.yiiframework.com/ 8 | rem @copyright Copyright © 2012 Yii Software LLC 9 | rem @license http://www.yiiframework.com/license/ 10 | rem ------------------------------------------------------------- 11 | 12 | @setlocal 13 | 14 | set YII_PATH=%~dp0 15 | 16 | if "%PHP_COMMAND%" == "" set PHP_COMMAND=php.exe 17 | 18 | "%PHP_COMMAND%" "%YII_PATH%yii" %* 19 | 20 | @endlocal 21 | --------------------------------------------------------------------------------