Skip to content

Commit f236e86

Browse files
author
Bui Sy Nguyen
committed
[Done] Implement logout case
1 parent d6bba7d commit f236e86

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

fproject/authclient/OAuth2.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,15 +143,27 @@ public function getPublicKey()
143143
return $this->_publicKey;
144144
}
145145

146-
public function logout()
146+
/**
147+
* Logout the current user by identity
148+
* @param bool $globalLogout
149+
* @return bool
150+
* @throws \yii\authclient\InvalidResponseException
151+
* @throws \yii\base\Exception
152+
*/
153+
public function logout($globalLogout=true)
147154
{
148155
/** @var UserIdentity $identity */
149-
$identity = Yii::$app->user->getIdentity();
156+
$identity = Yii::$app->user->identity;
157+
$token = $this->getAccessToken()->token;
158+
if($globalLogout)
159+
Yii::$app->user->logout();
160+
150161
if($identity != null && !empty($identity->sid))
151162
{
152-
$headers = ['Authorization' => "Bearer " . $this->getAccessToken()->token];
163+
$headers = ['Authorization' => "Bearer " . $token];
153164
$params = ['sid' => $identity->sid];
154165
$this->sendRequest("GET", $this->logoutUrl, $params, $headers);
155166
}
167+
return true;
156168
}
157169
}

0 commit comments

Comments
 (0)