Last active
August 29, 2015 14:21
-
-
Save jtopjian/7ad5b1466c6b36a2ad4a to your computer and use it in GitHub Desktop.
ownCloud Keystone Authentication
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| "user_backends" => array ( | |
| 0 => array ( | |
| "class" => "OC_User_Keystone", | |
| "arguments" => array ( | |
| 0 => 'https://keystone.example.com:35357/v2.0' | |
| ), | |
| ), | |
| ), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Copyright (c) 2015 Joe Topjian <[email protected]> | |
| * This file is licensed under the Affero General Public License version 3 or | |
| * later. | |
| * See the COPYING-README file. | |
| */ | |
| /** | |
| * User authentication against an OpenStack Keystone server | |
| * | |
| * @category Apps | |
| * @package UserExternal | |
| * @author Joe Topjian <[email protected]> | |
| * @license http://www.gnu.org/licenses/agpl AGPL | |
| * @link http://github.com/owncloud/apps | |
| */ | |
| class OC_User_Keystone extends \OCA\user_external\Base{ | |
| private $host; | |
| /** | |
| * Create new Keystone authentication provider | |
| * | |
| * @param string $host Host / URL to Keystone server. | |
| */ | |
| public function __construct($host) { | |
| $this->host=$host; | |
| parent::__construct($this->host); | |
| } | |
| /** | |
| * Check if the password is correct without logging in the user | |
| * | |
| * @param string $uid The username | |
| * @param string $password The password | |
| * | |
| * @return true/false | |
| */ | |
| public function checkPassword($uid, $password) { | |
| $client = new OpenCloud\OpenStack($this->host, array( | |
| 'username' => $uid, | |
| 'password' => $password, | |
| )); | |
| try { | |
| $json = $client->getCredentials(); | |
| $service = $client->identityService(); | |
| $response = $service->generateToken($json); | |
| $jsonBody = $response->json(); | |
| if (isset($jsonBody['access']['token']['id'])) { | |
| $this->storeUser($uid); | |
| return $uid; | |
| } else { | |
| return false; | |
| } | |
| } catch (Exception $e) { | |
| OCP\Util::writeLog( | |
| 'user_external', 'ERROR: keystone login failed for user ' . $uid, | |
| OCP\Util::ERROR | |
| ); | |
| return false; | |
| } | |
| return false; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment