├── .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 | [](https://packagist.org/packages/callmenp/lara-auth-bridge) [](https://packagist.org/packages/callmenp/lara-auth-bridge) [](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 |