From 161c43394261db7c6d65bb47e52e8db5bc99710a Mon Sep 17 00:00:00 2001 From: Techseria Developers Date: Mon, 18 Dec 2017 17:53:04 +0530 Subject: [PATCH] Update code for adding delete user code --- composer.json | 2 +- src/GluuClient.php | 24 ++++++++++++++++++++++++ src/Http/Request.php | 11 +++++++++++ src/Models/User.php | 3 +++ 4 files changed, 39 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index bd18e82..8772aa3 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,7 @@ }, "extra": { "branch-alias": { - "dev-master": "1.0.9-dev" + "dev-master": "1.0.11-dev" } }, "config": { diff --git a/src/GluuClient.php b/src/GluuClient.php index ad0b53c..8dd0551 100644 --- a/src/GluuClient.php +++ b/src/GluuClient.php @@ -248,6 +248,30 @@ public function updateUser($id,\Mrpvision\Gluu\Models\User $user) { throw new Models\Exception\UserException("Getting code {$ex->getCode()} from SSO server in updating user."); } } + public function DeleteUser($id) { + $accessToken = $this->requestTokens(); + $endpoint = $this->getProviderConfigValue("user_endpoint").'/' . $id; + $options = [ + "headers" => [ + "Authorization" => sprintf('Bearer %s', $accessToken->getToken()), + ] + ]; + + try { + $this->getOptions($options); + $response = $this->httpClient->delete( + $endpoint, $options + ); + if ($response->getStatusCode() == 204) { + return true; + } + throw new Exception\SSOException("Getting code {$response->getStatusCode()} from SSO server while creating an user's information."); + } catch (\Exception $ex) { + throw new Models\Exception\UserException("Getting code {$ex->getCode()} from SSO server in deleting user."); + } catch (\GuzzleHttp\Exception\ClientException $ex) { + throw new Models\Exception\UserException("Getting code {$ex->getCode()} from SSO server in deleting user."); + } + } public function CreateUser(\Mrpvision\Gluu\Models\User $user) { $accessToken = $this->requestTokens(); diff --git a/src/Http/Request.php b/src/Http/Request.php index 23ed361..4422743 100644 --- a/src/Http/Request.php +++ b/src/Http/Request.php @@ -86,6 +86,17 @@ public function put($requestUri, array $options = []) { return $res = $this->client->request('PUT', $requestUri,$options); } + /** + * @param string $requestUri + * @param array $postData + * @param array $requestHeaders + * + * @return Request + */ + public function delete($requestUri, array $options = []) + { + return $res = $this->client->request('DELETE', $requestUri,$options); + } /** * @param string $key diff --git a/src/Models/User.php b/src/Models/User.php index c01b202..e2adbc9 100644 --- a/src/Models/User.php +++ b/src/Models/User.php @@ -218,6 +218,9 @@ public function update(\Mrpvision\Gluu\GluuClient $gluu){ public function save(\Mrpvision\Gluu\GluuClient $gluu){ return $gluu->CreateUser($this); } + public function delete(\Mrpvision\Gluu\GluuClient $gluu){ + return $gluu->DeleteUser($this->id); + } }