Ejemplo n.º 1
0
 /**
  *
  * @param  Application            $app
  * @param  User                   $user
  * @param  type                   $name
  * @return API_OAuth2_Application
  */
 public static function create(Application $app, User $user = null, $name)
 {
     $sql = '
         INSERT INTO api_applications (
             application_id, creator, created_on, name, last_modified,
             nonce, client_id, client_secret, activated, grant_password
         )
         VALUES (
             null, :usr_id, NOW(), :name, NOW(), :nonce, :client_id,
             :client_secret, :activated, :grant_password
         )';
     $nonce = random::generatePassword(6);
     $client_secret = API_OAuth2_Token::generate_token();
     $client_token = API_OAuth2_Token::generate_token();
     $params = [':usr_id' => $user ? $user->getId() : null, ':name' => $name, ':client_id' => $client_token, ':client_secret' => $client_secret, ':nonce' => $nonce, ':activated' => 1, ':grant_password' => 0];
     $stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql);
     $stmt->execute($params);
     $stmt->closeCursor();
     $application_id = $app['phraseanet.appbox']->get_connection()->lastInsertId();
     $application = new self($app, $application_id);
     if ($user) {
         API_OAuth2_Account::create($app, $user, $application);
     }
     return $application;
 }
Ejemplo n.º 2
0
 public function testGenerate_token()
 {
     for ($i = 0; $i < 100; $i++) {
         $this->assertMd5(API_OAuth2_Token::generate_token());
     }
 }