public function __construct() { require_once 'PmPdo.php'; $this->scope = array('view_processes' => 'View Processes', 'edit_processes' => 'Edit Processes', '*' => '*'); // $dsn is the Data Source Name for your database, for exmaple "mysql:dbname=my_oauth2_db;host=localhost" $cnn = array('dsn' => self::$dsn, 'username' => self::$dbUser, 'password' => self::$dbPassword); if (self::$isRBAC) { $config = array(); $cnnrbac = array('dsn' => self::$dsnRBAC, 'username' => self::$dbUserRBAC, 'password' => self::$dbPasswordRBAC); $this->storage = new PmPdo($cnn, $config, $cnnrbac); } else { $this->storage = new PmPdo($cnn); } // Pass a storage object or array of storage objects to the OAuth2 server class $this->server = new \OAuth2\Server($this->storage, array('allow_implicit' => true, 'access_lifetime' => 86400)); $this->server->setConfig('enforce_state', false); // Add the "Authorization Code" grant type (this is where the oauth magic happens) $this->server->addGrantType(new \OAuth2\GrantType\AuthorizationCode($this->storage)); // Add the "Client Credentials" grant type (it is the simplest of the grant types) $this->server->addGrantType(new \ProcessMaker\Services\OAuth2\PmClientCredentials($this->storage)); // Add the "Refresh token" grant type $this->server->addGrantType(new \OAuth2\GrantType\RefreshToken($this->storage, array("always_issue_new_refresh_token" => true))); // create some users in memory //$users = array('bshaffer' => array('password' => 'brent123', 'first_name' => 'Brent', 'last_name' => 'Shaffer')); // create a storage object //$storage = new \OAuth2\Storage\Memory(array('user_credentials' => $users)); // create the grant type $grantType = new \OAuth2\GrantType\UserCredentials($this->storage); // add the grant type to your OAuth server $this->server->addGrantType($grantType); $scope = new \OAuth2\Scope(array('supported_scopes' => array_keys($this->scope))); $this->server->setScopeUtil($scope); }
private function getTestServer() { $storage = new OAuth2_Storage_Memory(json_decode(file_get_contents(dirname(__FILE__) . '/../../config/storage.json'), true)); $server = new OAuth2_Server($storage); $server->addGrantType(new OAuth2_GrantType_AuthorizationCode($storage)); return $server; }
private function getTestServer() { $storage = OAuth2_Storage_Bootstrap::getInstance()->getMemoryStorage(); $server = new OAuth2_Server($storage); $server->addGrantType(new OAuth2_GrantType_UserCredentials($storage)); return $server; }
public function getOAuthServer() { if (is_null($this->oauthServer)) { $config = array('client_table' => 'ohrm_oauth_client', 'access_token_table' => 'ohrm_oauth_access_token', 'refresh_token_table' => 'ohrm_oauth_refresh_token', 'code_table' => 'ohrm_oauth_authorization_code', 'user_table' => 'ohrm_oauth_user', 'jwt_table' => 'ohrm_oauth_jwt'); $conn = Doctrine_Manager::connection()->getDbh(); $storage = new OAuth2_Storage_Pdo($conn, $config); $server = new OAuth2_Server($storage); // $server->addGrantType(new OAuth2_GrantType_AuthorizationCode($storage)); //$server->addGrantType(new OAuth2_GrantType_ClientCredentials($storage)); $server->addGrantType(new OAuth2_GrantType_UserCredentials(new OAuth2_Storage_OhrmUserCredentials())); $server->addGrantType(new OAuth2_GrantType_RefreshToken($storage)); // or any grant type you like! $this->oauthServer = $server; } return $this->oauthServer; }
private function getTestServer() { $storage = OAuth2_Storage_Bootstrap::getInstance()->getMemoryStorage(); $server = new OAuth2_Server($storage); $server->addGrantType(new OAuth2_GrantType_AuthorizationCode($storage)); // or some other grant type. This is the simplest return $server; }
private function getTestServer($config = array()) { $storage = OAuth2_Storage_Bootstrap::getInstance()->getMemoryStorage(); $server = new OAuth2_Server($storage, $config); // Add the two types supported for authorization grant $server->addGrantType(new OAuth2_GrantType_AuthorizationCode($storage)); return $server; }
public function testGetGrantServerAccessTokenStorageAndClientCredentialsStorageAndGrantTypes() { $server = new OAuth2_Server(); $server->addStorage($this->getMock('OAuth2_Storage_AccessTokenInterface')); $server->addStorage($this->getMock('OAuth2_Storage_ClientCredentialsInterface')); $server->addGrantType($this->getMockBuilder('OAuth2_GrantType_AuthorizationCode')->disableOriginalConstructor()->getMock()); $server->getTokenController(); }
private function getTestServer($config = array()) { $storage = new OAuth2_Storage_Memory(json_decode(file_get_contents(dirname(__FILE__) . '/../../../config/storage.json'), true)); $server = new OAuth2_Server($storage, $config); // Add the two types supported for authorization grant $server->addGrantType(new OAuth2_GrantType_AuthorizationCode($storage)); return $server; }
private function getTestServer($audience = 'http://myapp.com/oauth/auth') { $storage = new OAuth2_Storage_Memory(json_decode(file_get_contents(dirname(__FILE__) . '/../../config/storage.json'), true)); $server = new OAuth2_Server($storage); $server->addGrantType(new OAuth2_GrantType_JWTBearer($storage, $audience)); return $server; }
private function getTestServer($audience = 'http://myapp.com/oauth/auth') { $storage = OAuth2_Storage_Bootstrap::getInstance()->getMemoryStorage(); $server = new OAuth2_Server($storage); $server->addGrantType(new OAuth2_GrantType_JWTBearer($storage, $audience)); return $server; }
<?php OAuth2_Autoloader::register(); // create your storage again $storage = new OAuth2_Storage_Pdo(array('dsn' => $dsn, 'username' => $username, 'password' => $password)); // create your server again $server = new OAuth2_Server($storage); // Add the "Authorization Code" grant type (this is required for authorization flows) $server->addGrantType(new OAuth2_GrantType_AuthorizationCode($storage)); $request = OAuth2_Request::createFromGlobals(); $response = new OAuth2_Response();