Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezprest_token.php
Go to the documentation of this file.
1 <?php
16 class ezpRestToken implements ezcPersistentObject
17 {
23 public $id;
29 public $refresh_token;
35 public $expirytime;
41 public $client_id;
47 public $user_id;
53 public $scope;
54
61 public function setState( array $state )
62 {
63 foreach ( $state as $attribute => $value )
64 {
65 $this->$attribute = $value;
66 }
67 }
68
74 public function getState()
75 {
76 return array(
77 'id' => $this->id,
78 'refresh_token' => $this->refresh_token,
79 'expirytime' => $this->expirytime,
80 'client_id' => $this->client_id,
81 'user_id' => $this->user_id,
82 'scope' => $this->scope,
83 );
84 }
85
93 public static function generateToken( $vary )
94 {
95 mt_srand( base_convert( substr( md5( $vary ), 0, 6 ), 36, 10 ) * microtime( true ) );
96 $a = base_convert( mt_rand(), 10, 36 );
97 $b = base_convert( mt_rand(), 10, 36 );
98 $token = substr( $b . $a, 1, 8 );
99 $tokenHash = sha1( $token );
100
101 return $tokenHash;
102 }
103
110 public static function fetch( $accessToken, $authCheck = true )
111 {
112 $tokenInfo = null;
113 $session = ezcPersistentSessionInstance::get();
114 $q = $session->createFindQuery( __CLASS__ );
115 $e = $q->expr;
116
117 $q->innerJoin( 'ezprest_clients', 'ezprest_token.client_id', 'ezprest_clients.client_id' );
118 if ( $authCheck )
119 {
120 $q->innerJoin( 'ezprest_authorized_clients', $e->lAnd( $e->eq( 'ezprest_authorized_clients.rest_client_id', 'ezprest_clients.id' ),
121 $e->eq( 'ezprest_authorized_clients.user_id', 'ezprest_token.user_id' ) ) );
122 }
123
124 $q->where( $q->expr->eq( 'ezprest_token.id', $q->bindValue( $accessToken ) ) );
125 $tokenInfo = $session->find( $q, 'ezpRestToken' );
126 if ( !empty( $tokenInfo ) )
127 {
128 $tokenInfo = array_shift( $tokenInfo );
129 }
130 else // Empty array. For consistency in result, cast it to null
131 {
132 $tokenInfo = null;
133 }
134
135 return $tokenInfo;
136 }
137 }
138 ?>
$session
$session
Definition: admin/articlelist.php:44
ezpRestToken
Definition: ezprest_token.php:17
ezpRestToken\$refresh_token
$refresh_token
Definition: ezprest_token.php:29
ezpRestToken\$user_id
$user_id
Definition: ezprest_token.php:47
ezpRestToken\$id
$id
Definition: ezprest_token.php:23
ezpRestToken\generateToken
static generateToken( $vary)
Definition: ezprest_token.php:93
ezpRestToken\$client_id
$client_id
Definition: ezprest_token.php:41
ezpRestToken\$scope
$scope
Definition: ezprest_token.php:53
ezpRestToken\fetch
static fetch( $accessToken, $authCheck=true)
Definition: ezprest_token.php:110
ezpRestToken\$expirytime
$expirytime
Definition: ezprest_token.php:35
ezpRestToken\getState
getState()
Definition: ezprest_token.php:74
ezpRestToken\setState
setState(array $state)
Definition: ezprest_token.php:61
$q
$q
Definition: modules/oauthadmin/list.php:17
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.