Skip to content

Commit 3044d1c

Browse files
committed
Added token check when token is passed to main object
1 parent 3058752 commit 3044d1c

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/TrustPilot/Api/Authorize.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function createPasswordToken($username = '', $password = '')
6262
{
6363
$data = array('username' => $username, 'password' => $password);
6464
$this->token = $this->createToken('password', $data);
65-
var_dump($this->token);
65+
return $this->token;
6666
}
6767

6868
/**
@@ -88,7 +88,7 @@ public function createAuthToken($code = '', $redirect_uri = '')
8888
{
8989
$data = array('code' => $code, 'redirect_uri' => $redirect_uri);
9090
$this->token = $this->createToken('authorization_code', $data);
91-
var_dump($this->token);
91+
return $this->token;
9292
}
9393

9494
/**
@@ -131,6 +131,7 @@ public function refreshToken()
131131
));
132132

133133
$this->token = $response;
134+
134135
}
135136

136137
/**
@@ -139,11 +140,14 @@ public function refreshToken()
139140
* @param
140141
* @return
141142
*/
142-
public function validateToken()
143+
public function isRefreshedToken()
143144
{
145+
144146
if(!$this->isValidToken()){
145147
$this->refreshToken();
148+
return true;
146149
}
150+
return false;
147151
}
148152

149153
/**

src/TrustPilot/TrustPilot.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ public function __construct($apiKey, $secret, $endpoint = null)
7777
public function setToken($token)
7878
{
7979
$this->token = $token;
80+
$auth = $this->authorize();
81+
$auth->setToken($this->token);
82+
if($auth->isRefreshedToken()){
83+
$this->token = $auth->getToken();
84+
}
8085
}
8186

8287
/**

0 commit comments

Comments
 (0)