Exemple #1
0
 /**
  * Stage 3: Client directly calls this api to exchange access token
  *
  * It can then use this access token to make calls to protected api
  *
  * @format JsonFormat,UploadFormat
  */
 public function postToken($request = null, $returnResponse = false)
 {
     // Handle a request for an OAuth2.0 Access Token and send the response to the client
     if ($request == null) {
         $request = \OAuth2\Request::createFromGlobals();
     }
     $response = $this->server->handleTokenRequest($request);
     //Set/Get token //PmPdo->setAccessToken()
     $token = $response->getParameters();
     if (array_key_exists('access_token', $token) && array_key_exists('refresh_token', $token)) {
         if ($request == null) {
             session_start();
         }
         $data = $this->storage->getAccessToken($token['access_token']);
         // verify if the client is our local PM Designer client
         if ($data['client_id'] == self::getPmClientId()) {
             //error_log('do stuff - is a request from local pm client');
             //require_once "classes/model/PmoauthUserAccessTokens.php";
             $userToken = new \PmoauthUserAccessTokens();
             $userToken->setAccessToken($token['access_token']);
             $userToken->setRefreshToken($token['refresh_token']);
             $userToken->setUserId($data['user_id']);
             $userToken->setSessionId(session_id());
             $userToken->setSessionName(session_name());
             $userToken->save();
         }
     }
     if ($returnResponse) {
         return $response;
     } else {
         $response->send();
         exit(0);
     }
 }
 public function testCustomClientAssertionType()
 {
     $request = OAuth2_Request_TestRequest::createPost(array('grant_type' => 'authorization_code', 'client_id' => 'Test Client ID', 'code' => 'testcode'));
     // verify the mock clientAssertionType was called as expected
     $clientAssertionType = $this->getMock('OAuth2_ClientAssertionTypeInterface', array('validateRequest', 'getClientId'));
     $clientAssertionType->expects($this->once())->method('validateRequest')->will($this->returnValue(true));
     $clientAssertionType->expects($this->once())->method('getClientId')->will($this->returnValue('Test Client ID'));
     // create mock storage
     $storage = OAuth2_Storage_Bootstrap::getInstance()->getMemoryStorage();
     $server = new OAuth2_Server(array($storage), array(), array(), array(), null, null, $clientAssertionType);
     $server->handleTokenRequest($request, $response = new OAuth2_Response());
 }