Ejemplo n.º 1
0
 public function setUp()
 {
     parent::setUp();
     $account = API_OAuth2_Account::load_with_user(self::$DI['app'], self::$DI['oauth2-app-user'], self::$DI['user']);
     try {
         new API_OAuth2_Token(self::$DI['app']['phraseanet.appbox'], $account);
         $this->fail();
     } catch (Exception $e) {
     }
     $this->object = API_OAuth2_Token::create(self::$DI['app']['phraseanet.appbox'], $account);
 }
Ejemplo n.º 2
0
 /**
  *
  * @return API_OAuth2_Token
  */
 public function get_token()
 {
     if (!$this->token) {
         try {
             $this->token = new API_OAuth2_Token($this->app['phraseanet.appbox'], $this);
         } catch (NotFoundHttpException $e) {
             $this->token = API_OAuth2_Token::create($this->app['phraseanet.appbox'], $this);
         }
     }
     return $this->token;
 }
Ejemplo n.º 3
0
 /**
  *
  * @param  type               $oauth_token
  * @param  type               $account_id
  * @param  type               $expires
  * @param  string             $scope
  * @return API_OAuth2_Adapter
  */
 protected function setAccessToken($oauth_token, $account_id, $expires, $scope = NULL)
 {
     $account = new API_OAuth2_Account($this->app, $account_id);
     $token = API_OAuth2_Token::create($this->app['phraseanet.appbox'], $account, $scope);
     $token->set_value($oauth_token)->set_expires($expires);
     return $this;
 }
Ejemplo n.º 4
0
 /**
  * Authorize application to use a grant password type
  *
  * @param  Application  $app     A Silex application where the controller is mounted on
  * @param  Request      $request The current request
  * @param  integer      $id      The application id
  * @return JsonResponse
  */
 public function renewAccessToken(Application $app, Request $request, $id)
 {
     if (!$request->isXmlHttpRequest() || !array_key_exists($request->getMimeType('json'), array_flip($request->getAcceptableContentTypes()))) {
         $app->abort(400, 'Bad request format, only JSON is allowed');
     }
     $error = false;
     $accessToken = null;
     try {
         $clientApp = new \API_OAuth2_Application($app, $id);
         $account = $clientApp->get_user_account($app['authentication']->getUser());
         $token = $account->get_token();
         if ($token instanceof \API_OAuth2_Token) {
             $token->renew();
         } else {
             $token = \API_OAuth2_Token::create($app['phraseanet.appbox'], $account);
         }
         $accessToken = $token->get_value();
     } catch (\Exception $e) {
         $error = true;
     }
     return $app->json(['success' => !$error, 'token' => $accessToken]);
 }