private function getTestServer()
 {
     $storage = OAuth2_Storage_Bootstrap::getInstance()->getMemoryStorage();
     $server = new OAuth2_Server($storage);
     $server->addGrantType(new OAuth2_GrantType_UserCredentials($storage));
     return $server;
 }
 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_AuthorizationCode($storage));
     // or some other grant type.  This is the simplest
     return $server;
 }
Beispiel #4
0
 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;
 }
Beispiel #5
0
 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;
 }
Beispiel #6
0
    /**
     * Access verification method.
     *
     * API access will be denied when this method returns false
     *
     * @return boolean true when api access is allowed; false otherwise
     */
    public function __isAllowed()
    {
        $request = \OAuth2\Request::createFromGlobals();
        $allowed = $this->server->verifyResourceRequest($request);
        $token = $this->server->getAccessTokenData($request);
        self::$userId = $token['user_id'];
        // Session handling to prevent session lose in other places like, home, admin, etc
        // when user is using the new designer that have not session because it is using only the API

        if ($allowed && $token['client_id'] == self::getPmClientId()) {

            $pmAccessToken = new \PmoauthUserAccessTokens();
            $session = $pmAccessToken->getSessionData($token['ACCESS_TOKEN']);

            if ($session !== false &&  array_key_exists($session->getSessionName(), $_COOKIE)) {
                // increase the timeout for local php session cookie
                $config = \Bootstrap::getSystemConfiguration();
                if (isset($config['session.gc_maxlifetime'])) {
                    $lifetime = $config['session.gc_maxlifetime'];
                } else {
                    $lifetime = ini_get('session.gc_maxlifetime');
                }
                if (empty($lifetime)) {
                    $lifetime = 1440;
                }

                setcookie($session->getSessionName(), $_COOKIE[$session->getSessionName()], time() + $lifetime, "/", null, false, true);
            }
        }

        return $allowed;
    }
 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;
 }
 /**
  * @expectedException InvalidArgumentException OAuth2_ResponseType_AuthorizationCodeInterface
  **/
 public function testAddingUnknownResponseTypeThrowsException()
 {
     $server = new OAuth2_Server();
     $server->addResponseType($this->getMock('OAuth2_ResponseTypeInterface'));
 }
 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;
 }
 public function testAddingStorageWithValidKeyOnlySetsThatKey()
 {
     if (version_compare(phpversion(), '5.3', '<')) {
         // cannot run this test in 5.2
         return;
     }
     $server = new OAuth2_Server();
     $server->addStorage($this->getMock('OAuth2_Storage_Memory'), 'access_token');
     $reflection = new ReflectionClass($server);
     $prop = $reflection->getProperty('storages');
     $prop->setAccessible(true);
     $storages = $prop->getValue($server);
     // get the private "storages" property
     $this->assertEquals(1, count($storages));
     $this->assertTrue(isset($storages['access_token']));
     $this->assertFalse(isset($storages['authorization_code']));
 }
<?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();