'Keycloak Rest API get all available resources
i am trying to list all resources client have access to. I am unable to figure out how to to make the call. I have used this curl
curl -X GET \
http://$URL/auth/realms/$RELM/authz/resource-server/resource \
-H 'Authorization: Bearer$TOKEN' \
-H 'cache-control: no-cache'
so far but i am getting this response : {"error":"RESTEASY003210: Could not find resource for full path: http://localhost:8070/auth/realms/argo/authz/resource-server/resource"}
Can someone help me to figure out how i can list all resources and if resource is not in the list to create new one ?
SOLUTION that is implementd:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->keyCloakURL . '/realms/' . $this->relmName . '/protocol/openid-connect/token');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,
"audience=" . KEYCLOAK_CLIENT_NAME . "&grant_type=urn:ietf:params:oauth:grant-type:uma-ticket&response_include_resource_name=true");
$authorization = "Authorization: Bearer " . $user_token['access_token'];
curl_setopt($ch, CURLOPT_HTTPHEADER, array (
'Content-Type: application/x-www-form-urlencoded',
$authorization
));
$result = curl_exec($ch);
if(curl_errno($ch))
{
echo 'curl error';
return false;
}
$result = json_decode($result, true);
curl_close($ch);
if(isset($result['access_token']) && !empty($result['access_token']))
{
$parts = explode('.', $result['access_token']);
if(!isset($parts[1]))
{
return false;
}
$info = $this->base64UrlDecode($parts[1]);
$info = json_decode($info, true);
$return = array ();
if(isset($info['authorization']['permissions']))
{
$permissions = $info['authorization']['permissions'];
foreach($permissions as $ecahPermission)
{
if(isset($ecahPermission['scopes']))
{
// $scopes = array_map('strtolower', $ecahPermission['scopes']);
$return[$ecahPermission['rsname']] = $ecahPermission['scopes'];
}
}
}
return $return;
}
return false;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|