Skip to content
This repository has been archived by the owner on Aug 9, 2022. It is now read-only.

Commit

Permalink
create dedicated ClientSecret class
Browse files Browse the repository at this point in the history
  • Loading branch information
Satya Kresna committed Apr 6, 2022
1 parent b5970d4 commit 04a1468
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 32 deletions.
32 changes: 0 additions & 32 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,38 +184,6 @@ public function delete($client_id)
);
}

// Get client secret
public function getSecret($id)
{
$curl = curl_init();

curl_setopt_array($curl, array(
CURLOPT_URL => "{$this->getAdminRealmUrl()}/clients/{$id}/client-secret",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => array(
'Authorization: Bearer '.$this->getToken()
),
));

$response = curl_exec($curl);
$httpcode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);

$result = '';

if ((int) $httpcode === 200) {
$result = isset(json_decode($response, true)['value']) ? json_decode($response, true)['value'] : '';
}

return $result;
}

public function getRawRoles($client_id, $params)
{
$curl = curl_init();
Expand Down
70 changes: 70 additions & 0 deletions src/ClientSecret.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

namespace RistekUSDI\ServiceAccount;

use RistekUSDI\ServiceAccount\Base;

class ClientSecret extends Base
{
public function get($client_id)
{
$curl = curl_init();

curl_setopt_array($curl, array(
CURLOPT_URL => "{$this->getAdminRealmUrl()}/clients/{$client_id}/client-secret",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => array(
'Authorization: Bearer '.$this->getToken()
),
));

$response = curl_exec($curl);
$httpcode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);

$result = '';

if ((int) $httpcode === 200) {
$result = isset(json_decode($response, true)['value']) ? json_decode($response, true)['value'] : '';
}

return $result;
}

public function update($client_id)
{
$curl = curl_init();

curl_setopt_array($curl, array(
CURLOPT_URL => "{$this->getAdminRealmUrl()}/clients/{$client_id}/client-secret",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => array(
'Authorization: Bearer '.$this->getToken()
),
));

$response = curl_exec($curl);
$httpcode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);

$result = '';

if ((int) $httpcode === 200) {
$result = isset(json_decode($response, true)['value']) ? json_decode($response, true)['value'] : '';
}

return $result;
}
}

0 comments on commit 04a1468

Please sign in to comment.