├── .gitignore ├── LICENSE ├── README.md ├── composer.json ├── phpbb3.0 └── includes │ └── auth │ ├── auth_bridgebb.php │ └── bridgebb │ ├── BridgeBB.php │ └── BridgeBBDBAL.php ├── phpbb3.1 ├── config │ └── parameters.yml └── ext │ ├── index.htm │ └── laravel │ └── bridgebb │ ├── auth │ └── provider │ │ └── bridgebb.php │ ├── composer.json │ ├── config │ └── services.yml │ └── ext.php └── src ├── CallMeNP └── LaraAuthBridge │ ├── Controllers │ └── ApiController.php │ └── LaraAuthBridgeServiceProvider.php └── config └── lara-auth-bridge.php /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | .idea/ -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | This package is unmaintained. 2 | 3 | I do not intend to continue development on this project due to changing priorities at my day job. I'll keep the repo up in case it is still useful to anyone. 4 | 5 | Thanks @Bukashk0zzz 6 | 7 | # Allows phpBB (3.0 & 3.1) auth over Laravel 5 8 | 9 | For Laravel 4.\* see [r-a-stone's work](https://github.com/r-a-stone/Laravel-Auth-Bridge) Auth driver to create/authenticate accounts. 10 | 11 | [![Latest Stable Version](https://poser.pugx.org/callmenp/lara-auth-bridge/v/stable)](https://packagist.org/packages/callmenp/lara-auth-bridge) [![Total Downloads](https://poser.pugx.org/callmenp/lara-auth-bridge/downloads)](https://packagist.org/packages/callmenp/lara-auth-bridge) [![License](https://poser.pugx.org/callmenp/lara-auth-bridge/license)](https://packagist.org/packages/callmenp/lara-auth-bridge) 12 | 13 | ### Installation 14 | #### Laravel 15 | ##### run composer 16 | ``` php 17 | composer require callmenp/lara-auth-bridge 18 | ``` 19 | ##### add service provider 20 | Register the Service Provider by adding it to your project's providers array in app.php 21 | ``` php 22 | 'providers' => array( 23 | 'CallMeNP\LaraAuthBridge\LaraAuthBridgeServiceProvider', 24 | ); 25 | ``` 26 | ##### edit config 27 | Change configs config/lara-auth-bridge.php 28 | ``` php 29 | // Create a secret app key in 30 | 'appkey' => 'yoursecretapikey' 31 | 32 | // Update the column names used for the Laravel Auth driver 33 | 'username_column' => 'user_login', 34 | 'password_column' => 'user_password' 35 | 36 | // Set true if you use multiAuth, false if default Laravel Auth 37 | 'client_auth' => false 38 | ``` 39 | ##### exclude URIs from CSRF protection 40 | In file app/Http/Middleware/VerifyCsrfToken.php add 41 | ``` php 42 | protected $except = [ 43 | 'auth-bridge/*', 44 | ]; 45 | ``` 46 | More info how to exclude uris on [laravel site](http://laravel.com/docs/master/routing#csrf-excluding-uris) 47 | 48 | #### phpBB 3.1 49 | ##### copy files 50 | Copy all files in the phpBB 3.1 directory to your phpBB install 51 | ##### edit config 52 | Edit the file located at {PHPBB-ROOT}/ext/laravel/bridgebb/auth/provider/bridgebb.php 53 | ``` php 54 | define('LARAVEL_URL', 'http://www.example.com'); //your laravel application's url 55 | define('BRIDGEBB_API_KEY', "yoursecretapikey"); //the same key you created earlier 56 | define ('LARAVEL_CUSTOM_USER_DATA', serialize ([ 57 | 'email' => 'user_email', 58 | 'dob' => 'user_birthday', 59 | ])); // Update the columns you want to come from Laravel user to phpBB user 60 | ``` 61 | ###### setting 62 | Login to the phpBB admin panel enable bridgebb extension and after set bridgebb as the authentication module 63 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "callmenp/lara-auth-bridge", 3 | "description": "Offers a simple API for the included custom phpBB authentication module. for phpBB3.0 and laravel5", 4 | "keywords": ["phpbb", "phpbb3", "bridge", "laravel", "laravel5"], 5 | "license": "MIT", 6 | "authors": [{ 7 | "name": "CallMeNP", 8 | "email": "np.liamg@gmail.com" 9 | }], 10 | "require": { 11 | "php": ">=5.4.0", 12 | "illuminate/support": "5.*" 13 | }, 14 | "autoload": { 15 | "psr-0": { 16 | "CallMeNP\\LaraAuthBridge": "src/" 17 | } 18 | }, 19 | "scripts": { 20 | "post-install-cmd": "php artisan vendor:publish callmenp/lara-auth-bridge" 21 | }, 22 | "minimum-stability": "stable" 23 | } -------------------------------------------------------------------------------- /phpbb3.0/includes/auth/auth_bridgebb.php: -------------------------------------------------------------------------------- 1 | 'user_email', 13 | 'dob' => 'user_birthday', 14 | ])); 15 | 16 | require __DIR__.'/bridgebb/BridgeBBDBAL.php'; 17 | require __DIR__.'/bridgebb/BridgeBB.php'; 18 | 19 | // Login method 20 | function login_bridgebb($username, $password) 21 | { 22 | return Bridgebb::login($username, $password); 23 | } 24 | 25 | // If user auth on laravel side but not in phpBB try to auto login 26 | function autologin_bridgebb() 27 | { 28 | return Bridgebb::autologin(); 29 | } 30 | 31 | // Validates the current session. 32 | function validate_session_bridgebb($user_row) 33 | { 34 | if ($user_row['username'] == 'Anonymous') return false; 35 | return Bridgebb::validateSession($user_row); 36 | } 37 | 38 | // Logout 39 | function logout_bridgebb($user_row) 40 | { 41 | Bridgebb::logOut($user_row); 42 | } -------------------------------------------------------------------------------- /phpbb3.0/includes/auth/bridgebb/BridgeBB.php: -------------------------------------------------------------------------------- 1 | $username])) { 8 | return self::_success(LOGIN_SUCCESS, self::autologin()); 9 | } 10 | 11 | if (is_null($password)) { 12 | return self::_error(LOGIN_ERROR_PASSWORD, 'NO_PASSWORD_SUPPLIED'); 13 | } 14 | if (is_null($username)) { 15 | return self::_error(LOGIN_ERROR_USERNAME, 'LOGIN_ERROR_USERNAME'); 16 | } 17 | 18 | return self::_apiValidate($username, $password); 19 | } 20 | 21 | public static function autologin() 22 | { 23 | try { 24 | $request = self::_makeApiRequest([],'GET'); 25 | $oResponse = json_decode($request, true); 26 | 27 | if (isset($oResponse['data']['username']) && isset($oResponse['code'])) { 28 | if ($oResponse['code'] === '200' && $oResponse['data']['username']) { 29 | $row = BridgeBBDBAL::getUserByUsername($oResponse['data']['username']); 30 | return ($row)?$row:[]; 31 | } 32 | } 33 | return []; 34 | } catch (Exception $e) { 35 | return []; 36 | } 37 | } 38 | 39 | public static function validateSession($user_row) 40 | { 41 | try { 42 | $request = self::_makeApiRequest([],'GET'); 43 | $oResponse = json_decode($request, true); 44 | 45 | if (isset($oResponse['data']['username']) && isset($oResponse['code'])) { 46 | if ($oResponse['code'] === '200' && $oResponse['data']['username']) { 47 | return ($user_row['username'] == $oResponse['data']['username'])?true:false; 48 | } 49 | } 50 | 51 | return false; 52 | } catch (Exception $e) { 53 | return false; 54 | } 55 | } 56 | 57 | public static function logOut($user_row) 58 | { 59 | try { 60 | if (self::validateSession($user_row)) { 61 | self::_makeApiRequest([],'DELETE'); 62 | } 63 | } catch (Exception $e) { 64 | } 65 | } 66 | 67 | private static function _makeApiRequest($data,$method) { 68 | $ch = curl_init(); 69 | $cooks = ''; 70 | foreach ($_COOKIE as $k=>$v) { 71 | $cooks .= $k.'='.$v.';'; 72 | } 73 | 74 | $curlConfig = [ 75 | CURLOPT_URL => LARAVEL_URL.'/auth-bridge/login', 76 | CURLOPT_COOKIESESSION => true, 77 | CURLOPT_COOKIE => $cooks, 78 | CURLINFO_HEADER_OUT => true, 79 | CURLOPT_HEADERFUNCTION => 'curlResponseHeaderCallback', 80 | CURLOPT_RETURNTRANSFER => true 81 | ]; 82 | 83 | if ($method == 'POST') { 84 | $curlConfig[CURLOPT_POST] = true; 85 | $curlConfig[CURLOPT_POSTFIELDS] = $data; 86 | } elseif ($method == 'DELETE') { 87 | $curlConfig[CURLOPT_CUSTOMREQUEST] = 'DELETE'; 88 | } 89 | 90 | curl_setopt_array($ch, $curlConfig); 91 | $result = curl_exec($ch); 92 | curl_close($ch); 93 | return $result; 94 | } 95 | 96 | private static function _apiValidate($username, $password) 97 | { 98 | try { 99 | $postdata = http_build_query( 100 | array( 101 | 'appkey' => BRIDGEBB_API_KEY, 102 | 'username' => $username, 103 | 'password' => $password 104 | ) 105 | ); 106 | $request = self::_makeApiRequest($postdata,'POST'); 107 | 108 | $oResponse = json_decode($request, true); 109 | if ($oResponse['code'] === '200') { 110 | return self::_handleAuthSuccess($username, $password, $oResponse['data']); 111 | } else { 112 | return self::_error(LOGIN_ERROR_USERNAME, 'LOGIN_ERROR_USERNAME'); 113 | } 114 | } catch (Exception $e) { 115 | return self::_error(LOGIN_ERROR_EXTERNAL_AUTH, $e->getMessage()); 116 | } 117 | } 118 | 119 | private static function _handleAuthSuccess($username, $password, $user_laravel) 120 | { 121 | $row = BridgeBBDBAL::getUserByUsername($username); 122 | // Does User exist? 123 | if ($row) { 124 | // User inactive 125 | if ($row['user_type'] == USER_INACTIVE || $row['user_type'] == USER_IGNORE) { 126 | return self::_error(LOGIN_ERROR_ACTIVE, 'ACTIVE_ERROR', $row); 127 | } else { 128 | // Session hack 129 | header("Location: http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); 130 | die(); 131 | // return self::_success(LOGIN_SUCCESS, $row); 132 | } 133 | } else { 134 | // this is the user's first login so create an empty profile 135 | user_add(self::createUserRow($username, sha1($password), $user_laravel)); 136 | // Session hack 137 | header("Location: http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); 138 | die(); 139 | // return self::_success(LOGIN_SUCCESS_CREATE_PROFILE, $newUser); 140 | } 141 | } 142 | 143 | public static function createUserRow($username, $password, $user_laravel) 144 | { 145 | global $user; 146 | // first retrieve default group id 147 | $row = BridgeBBDBAL::getDefaultGroupID(); 148 | if (!$row) { 149 | trigger_error('NO_GROUP'); 150 | } 151 | 152 | // generate user account data 153 | $userRow = array( 154 | 'username' => $username, 155 | 'user_password' => phpbb_hash($password), 156 | 'group_id' => (int) $row['group_id'], 157 | 'user_type' => USER_NORMAL, 158 | 'user_ip' => $user->ip, 159 | ); 160 | 161 | if (LARAVEL_CUSTOM_USER_DATA && $laravel_fields = unserialize(LARAVEL_CUSTOM_USER_DATA)) { 162 | foreach ($laravel_fields as $key => $value) { 163 | if (isset($user_laravel[$key])) { 164 | $userRow[$value] = $user_laravel[$key]; 165 | } 166 | } 167 | } 168 | return $userRow; 169 | } 170 | 171 | private static function _error($status, $message, $row = array('user_id' => ANONYMOUS)) 172 | { 173 | return array( 174 | 'status' => $status, 175 | 'error_msg' => $message, 176 | 'user_row' => $row, 177 | ); 178 | } 179 | 180 | private static function _success($status, $row) 181 | { 182 | return array( 183 | 'status' => $status, 184 | 'error_msg' => false, 185 | 'user_row' => $row, 186 | ); 187 | } 188 | } 189 | 190 | function curlResponseHeaderCallback($ch, $headerLine) { 191 | preg_match_all('/^Set-Cookie:\s*([^;]*)/mi', $headerLine, $matches); 192 | foreach($matches[1] as $item) { 193 | parse_str($item, $cookie); 194 | setcookie(key($cookie), $cookie[key($cookie)], time() + 86400, "/"); 195 | } 196 | return strlen($headerLine); // Needed by curl 197 | } 198 | -------------------------------------------------------------------------------- /phpbb3.0/includes/auth/bridgebb/BridgeBBDBAL.php: -------------------------------------------------------------------------------- 1 | sql_escape($username)."'"; 12 | $result = $db->sql_query($sql); 13 | $row = $db->sql_fetchrow($result); 14 | $db->sql_freeresult($result); 15 | return $row; 16 | } 17 | 18 | public static function getDefaultGroupID() 19 | { 20 | global $db; 21 | $sql = 'SELECT group_id 22 | FROM '.GROUPS_TABLE." 23 | WHERE group_name = '".$db->sql_escape('REGISTERED')."' 24 | AND group_type = ".GROUP_SPECIAL; 25 | $result = $db->sql_query($sql); 26 | $row = $db->sql_fetchrow($result); 27 | $db->sql_freeresult($result); 28 | 29 | return $row; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /phpbb3.1/config/parameters.yml: -------------------------------------------------------------------------------- 1 | parameters: 2 | # Disable the usage of the super globals (_GET, _POST, _SERVER...) 3 | core.disable_super_globals: false 4 | 5 | # Datetime class to use 6 | datetime.class: \phpbb\datetime 7 | 8 | # Mimetype guesser priorities 9 | mimetype.guesser.priority.lowest: -2 10 | mimetype.guesser.priority.low: -1 11 | mimetype.guesser.priority.default: 0 12 | mimetype.guesser.priority.high: 1 13 | mimetype.guesser.priority.highest: 2 14 | 15 | # List of default password driver types 16 | passwords.algorithms: 17 | - passwords.driver.bcrypt_2y 18 | - passwords.driver.bcrypt 19 | - passwords.driver.salted_md5 20 | - passwords.driver.phpass 21 | -------------------------------------------------------------------------------- /phpbb3.1/ext/index.htm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /phpbb3.1/ext/laravel/bridgebb/auth/provider/bridgebb.php: -------------------------------------------------------------------------------- 1 | 'user_email', 14 | 'dob' => 'user_birthday', 15 | ])); 16 | 17 | function curlResponseHeaderCallback($ch, $headerLine) { 18 | preg_match_all('/^Set-Cookie:\s*([^;]*)/mi', $headerLine, $matches); 19 | foreach($matches[1] as $item) { 20 | parse_str($item, $cookie); 21 | setcookie(key($cookie), $cookie[key($cookie)], time() + 86400, "/"); 22 | } 23 | return strlen($headerLine); // Needed by curl 24 | } 25 | } 26 | 27 | namespace laravel\bridgebb\auth\provider { 28 | class bridgebb extends \phpbb\auth\provider\base 29 | { 30 | 31 | public function __construct(\phpbb\db\driver\driver_interface $db) 32 | { 33 | $this->db = $db; 34 | } 35 | 36 | // Login method 37 | public function login($username, $password) 38 | { 39 | if (self::validate_session(['username'=>$username]) && $this->_getUserByUsername($username)) { 40 | return self::_success(LOGIN_SUCCESS, self::autologin()); 41 | } 42 | 43 | if (is_null($password)) { 44 | return self::_error(LOGIN_ERROR_PASSWORD, 'NO_PASSWORD_SUPPLIED'); 45 | } 46 | if (is_null($username)) { 47 | return self::_error(LOGIN_ERROR_USERNAME, 'LOGIN_ERROR_USERNAME'); 48 | } 49 | 50 | return self::_apiValidate($username, $password); 51 | } 52 | 53 | // If user auth on laravel side but not in phpBB try to auto login 54 | public function autologin() 55 | { 56 | try { 57 | $request = self::_makeApiRequest([],'GET'); 58 | $oResponse = json_decode($request, true); 59 | 60 | if (isset($oResponse['data']['username']) && isset($oResponse['code'])) { 61 | if ($oResponse['code'] === '200' && $oResponse['data']['username']) { 62 | $row = $this->_getUserByUsername($oResponse['data']['username']); 63 | return ($row)?$row:[]; 64 | } 65 | } 66 | return []; 67 | } catch (Exception $e) { 68 | return []; 69 | } 70 | } 71 | 72 | // Validates the current session. 73 | public function validate_session($user_row) 74 | { 75 | if ($user_row['username'] == 'Anonymous') return false; 76 | try { 77 | $request = self::_makeApiRequest([],'GET'); 78 | $oResponse = json_decode($request, true); 79 | 80 | if (isset($oResponse['data']['username']) && isset($oResponse['code'])) { 81 | if ($oResponse['code'] === '200' && $oResponse['data']['username']) { 82 | return (mb_strtolower($user_row['username']) == mb_strtolower($oResponse['data']['username']))?true:false; 83 | } 84 | } 85 | 86 | return false; 87 | } catch (Exception $e) { 88 | return false; 89 | } 90 | } 91 | 92 | // Logout 93 | public function logout($user_row, $new_session) 94 | { 95 | try { 96 | if (self::validate_session($user_row)) { 97 | self::_makeApiRequest([],'DELETE'); 98 | } 99 | } catch (Exception $e) { 100 | } 101 | } 102 | 103 | private function _makeApiRequest($data,$method) { 104 | $ch = curl_init(); 105 | $cooks = ''; 106 | foreach ($_COOKIE as $k=>$v) { 107 | $cooks .= $k.'='.$v.';'; 108 | } 109 | 110 | $curlConfig = [ 111 | CURLOPT_URL => LARAVEL_URL.'/auth-bridge/login', 112 | CURLOPT_COOKIESESSION => true, 113 | CURLOPT_COOKIE => $cooks, 114 | CURLINFO_HEADER_OUT => true, 115 | CURLOPT_HEADERFUNCTION => 'curlResponseHeaderCallback', 116 | CURLOPT_RETURNTRANSFER => true 117 | ]; 118 | 119 | if ($method == 'POST') { 120 | $curlConfig[CURLOPT_POST] = true; 121 | $curlConfig[CURLOPT_POSTFIELDS] = $data; 122 | } elseif ($method == 'DELETE') { 123 | $curlConfig[CURLOPT_CUSTOMREQUEST] = 'DELETE'; 124 | } 125 | 126 | curl_setopt_array($ch, $curlConfig); 127 | $result = curl_exec($ch); 128 | curl_close($ch); 129 | return $result; 130 | } 131 | 132 | private function _apiValidate($username, $password) 133 | { 134 | try { 135 | $postdata = http_build_query( 136 | array( 137 | 'appkey' => BRIDGEBB_API_KEY, 138 | 'username' => $username, 139 | 'password' => $password 140 | ) 141 | ); 142 | $request = self::_makeApiRequest($postdata,'POST'); 143 | 144 | $oResponse = json_decode($request, true); 145 | if ($oResponse['code'] === '200') { 146 | return self::_handleAuthSuccess($username, $password, $oResponse['data']); 147 | } else { 148 | return self::_error(LOGIN_ERROR_USERNAME, 'LOGIN_ERROR_USERNAME'); 149 | } 150 | } catch (Exception $e) { 151 | return self::_error(LOGIN_ERROR_EXTERNAL_AUTH, $e->getMessage()); 152 | } 153 | } 154 | 155 | private function _handleAuthSuccess($username, $password, $user_laravel) 156 | { 157 | if ($row = $this->_getUserByUsername($username)) { 158 | // User inactive 159 | if ($row['user_type'] == USER_INACTIVE || $row['user_type'] == USER_IGNORE) { 160 | return self::_error(LOGIN_ERROR_ACTIVE, 'ACTIVE_ERROR', $row); 161 | } else { 162 | // Session hack 163 | header("Location: http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); 164 | die(); 165 | //return self::_success(LOGIN_SUCCESS, $row); 166 | } 167 | } else { 168 | // this is the user's first login so create an empty profile 169 | user_add(self::_createUserRow($username, sha1($password), $user_laravel)); 170 | // Session hack 171 | header("Location: http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); 172 | die(); 173 | //return self::_success(LOGIN_SUCCESS_CREATE_PROFILE, $newUser); 174 | } 175 | } 176 | 177 | private function _createUserRow($username, $password, $user_laravel) 178 | { 179 | global $user; 180 | // first retrieve default group id 181 | $row = $this->_getDefaultGroupID(); 182 | if (!$row) { 183 | trigger_error('NO_GROUP'); 184 | } 185 | 186 | // generate user account data 187 | $userRow = array( 188 | 'username' => $username, 189 | 'user_password' => phpbb_hash($password), 190 | 'group_id' => (int) $row['group_id'], 191 | 'user_type' => USER_NORMAL, 192 | 'user_ip' => $user->ip, 193 | ); 194 | 195 | if (LARAVEL_CUSTOM_USER_DATA && $laravel_fields = unserialize(LARAVEL_CUSTOM_USER_DATA)) { 196 | foreach ($laravel_fields as $key => $value) { 197 | if (isset($user_laravel[$key])) { 198 | $userRow[$value] = $user_laravel[$key]; 199 | } 200 | } 201 | } 202 | return $userRow; 203 | } 204 | 205 | private function _error($status, $message, $row = array('user_id' => ANONYMOUS)) 206 | { 207 | return array( 208 | 'status' => $status, 209 | 'error_msg' => $message, 210 | 'user_row' => $row, 211 | ); 212 | } 213 | 214 | private function _success($status, $row) 215 | { 216 | return array( 217 | 'status' => $status, 218 | 'error_msg' => false, 219 | 'user_row' => $row, 220 | ); 221 | } 222 | 223 | private function _getUserByUsername($username) 224 | { 225 | global $db; 226 | $username = mb_strtolower($username); 227 | $sql = 'SELECT * 228 | FROM '.USERS_TABLE." 229 | WHERE LOWER(username) = '".$db->sql_escape($username)."'"; 230 | $result = $db->sql_query($sql); 231 | $row = $db->sql_fetchrow($result); 232 | $db->sql_freeresult($result); 233 | return $row; 234 | } 235 | 236 | private function _getDefaultGroupID() 237 | { 238 | global $db; 239 | $sql = 'SELECT group_id 240 | FROM '.GROUPS_TABLE." 241 | WHERE group_name = '".$db->sql_escape('REGISTERED')."' 242 | AND group_type = ".GROUP_SPECIAL; 243 | $result = $db->sql_query($sql); 244 | $row = $db->sql_fetchrow($result); 245 | $db->sql_freeresult($result); 246 | 247 | return $row; 248 | } 249 | } 250 | } -------------------------------------------------------------------------------- /phpbb3.1/ext/laravel/bridgebb/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "laravel/bridgebb", 3 | "type": "phpbb-extension", 4 | "description": "Bridging that auth from laravel5", 5 | "homepage": "https://github.com/CallMeNP/lara-auth-bridge", 6 | "version": "2.0.0", 7 | "time": "2015-09-25", 8 | "license": "MIT", 9 | "authors": [{ 10 | "name": "Denis Golubovskiy", 11 | "email": "bukashk0zzz@me.com", 12 | "homepage": "http://mysimple.name", 13 | "role": "Developer" 14 | }], 15 | "require": { 16 | "php": ">=5.3.3" 17 | }, 18 | "require-dev": { 19 | "phpbb/epv": "dev-master" 20 | }, 21 | "extra": { 22 | "display-name": "BridgeBB Laravel5 Authentication", 23 | "soft-require": { 24 | "phpbb/phpbb": ">=3.1.0-RC2,<3.2.*@dev" 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /phpbb3.1/ext/laravel/bridgebb/config/services.yml: -------------------------------------------------------------------------------- 1 | services: 2 | auth.provider.bridgebb: 3 | class: laravel\bridgebb\auth\provider\bridgebb 4 | arguments: 5 | - @dbal.conn 6 | tags: 7 | - { name: auth.provider } -------------------------------------------------------------------------------- /phpbb3.1/ext/laravel/bridgebb/ext.php: -------------------------------------------------------------------------------- 1 | input('appkey'); 14 | $username = $request->input('username'); 15 | $password = $request->input('password'); 16 | if ($appkey !== config('lara-auth-bridge.appkey')) { 17 | return response()->json(['code' => '400', 'msg' => 'Invalid API Key', 'data' => []]); 18 | } 19 | if ($data = $this->_validateCredentials($username, $password)) { 20 | return response()->json(['code' => '200', 'msg' => 'success', 'data' => $data]); 21 | } 22 | 23 | return response()->json(['code' => '400', 'msg' => 'Invalid username or password', 'data' => []]); 24 | } 25 | 26 | public function getSession() 27 | { 28 | if (config('lara-auth-bridge.client_auth') && Auth::client()->check()) { 29 | $result = ['username' => Auth::client()->user()[config('lara-auth-bridge.user_model.username_column')]]; 30 | } elseif (!config('lara-auth-bridge.client_auth') && Auth::check()) { 31 | $result = ['username' => Auth::user()[config('lara-auth-bridge.user_model.username_column')]]; 32 | } else { 33 | $result = []; 34 | } 35 | return response()->json(['code' => '200', 'data' => $result]); 36 | } 37 | 38 | public function doLogout() 39 | { 40 | if (config('lara-auth-bridge.client_auth') && Auth::client()->check()) { 41 | Auth::client()->logout(); 42 | } elseif (!config('lara-auth-bridge.client_auth') && Auth::check()) { 43 | Auth::logout(); 44 | } 45 | } 46 | 47 | private function _validateCredentials($username, $password) 48 | { 49 | $username = trim($username); 50 | $password = trim($password); 51 | 52 | if (config('lara-auth-bridge.client_auth') && Auth::client()->attempt([config('lara-auth-bridge.user_model.username_column')=>$username,config('lara-auth-bridge.user_model.password_column')=>$password]) 53 | || (!config('lara-auth-bridge.client_auth') && Auth::attempt([config('lara-auth-bridge.user_model.username_column')=>$username,config('lara-auth-bridge.user_model.password_column')=>$password]))) 54 | { 55 | return (config('lara-auth-bridge.client_auth'))?Auth::client()->user():Auth::user(); 56 | } 57 | 58 | return false; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/CallMeNP/LaraAuthBridge/LaraAuthBridgeServiceProvider.php: -------------------------------------------------------------------------------- 1 | publishes([ 23 | __DIR__.'/../../config/lara-auth-bridge.php' => config_path('lara-auth-bridge.php'), 24 | ], 'config'); 25 | 26 | Route::get('/auth-bridge/login', 'CallMeNP\LaraAuthBridge\Controllers\ApiController@getSession'); 27 | Route::post('/auth-bridge/login', 'CallMeNP\LaraAuthBridge\Controllers\ApiController@doLogin'); 28 | Route::delete('/auth-bridge/login', 'CallMeNP\LaraAuthBridge\Controllers\ApiController@doLogout'); 29 | } 30 | 31 | public function register() 32 | { 33 | // 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/config/lara-auth-bridge.php: -------------------------------------------------------------------------------- 1 | 'yoursecretapikey', 5 | 'client_auth' => false, 6 | 'user_model' => [ 7 | 'username_column' => 'email', 8 | 'password_column' => 'password', 9 | ], 10 | ]; 11 | --------------------------------------------------------------------------------