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;
Related
I am able to attach a single image via Jira Rest Api but it fails when i attempt to send multiple images through it. This is my code for single attachment. Need help to make multiple attachments work.
Reference:
Jira attach file to issue with PHP and CURL
$cfile = new CURLFile($attachment['tmp_name'],$attachment['type'], $attachment['name']);
$data = array('file' => $cfile);
$url = "{$uriapi}"."issue/"."{$bugid}"."/attachments";
curl_setopt_array(
$ch,
array(
CURLOPT_URL=>$url,
CURLOPT_POST=>true,
CURLOPT_VERBOSE=>1,
CURLOPT_POSTFIELDS=>$data,
CURLOPT_INFILESIZE => 10,
CURLOPT_SSL_VERIFYHOST=> 0,
CURLOPT_SSL_VERIFYPEER=> 0,
CURLOPT_RETURNTRANSFER=>true,
CURLOPT_HTTPHEADER=> $headers,
CURLOPT_USERPWD=>"$Jirausername:$Jirapassword"
)
);
$result=curl_exec($ch);
$ch_error = curl_error($ch);
if ($ch_error) {
echo "cURL Error: $ch_error";
return "Error Opening file. Failed to add Attachment";
}
elseif(isset($result)){
//return "Attachment added";
return "";
}
else{
return "Failed to add Attachment";
}
curl_close($ch);
}
The following code works fine for me, I hope it helps.
$username = "xxxxx";
$password = "xxxxx";
$url = "https://YourUrl/rest/api/latest/issue/YourKey/attachments";
$attachments = array("attachment1", "attachment2", "attachment3");
$curl = curl_init();
for ($i = 0; $i < count($attachments); $i++) {
$attachmentPath = "/your/attachment/path/$attachments[$i]";
$filename = array_pop(explode('/', $attachmentPath));
$cfile = new CURLFile($attachmentPath);
$cfile->setPostFilename($filename);
$data = array('file' => $cfile);
$headers = array(
'Content-Type: multipart/form-data',
'X-Atlassian-Token: nocheck'
);
curl_setopt($curl, CURLOPT_USERPWD, "$username:$password");
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($curl, CURLOPT_VERBOSE, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
$result = curl_exec($curl);
$ch_error = curl_error($curl);
if ($ch_error) {
echo "cURL Error: $ch_error";
} else {
echo $result;
}
}
curl_close($curl);
I'm having a bit of an issue, im trying to pull basic metadata from an external URL, I have successfuly got it to do so for the most part but its causing a few character issues on letters that are Ä ä ö are coming out like mäenjaksa7-300x200.jpg when i call the images url which is actually mäenjaksa7-300x200.jpg, my code is below and thank you for helping.
function file_get_contents_curl($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$data = curl_exec($ch);
curl_close($ch);
return $data; }
$html = file_get_contents_curl($params['url']);
//parsing begins here:
$doc = new DOMDocument();
#$doc->loadHTML($html);
$nodes = $doc->getElementsByTagName('title');
//get and display what you need:
$urltitle = $nodes->item(0)->nodeValue;
$metas = $doc->getElementsByTagName('meta');
for ($i = 0; $i < $metas->length; $i++)
{
$meta = $metas->item($i);
if($meta->getAttribute('name') == 'description')
$description = $meta->getAttribute('content');
if($meta->getAttribute('name') == 'keywords')
$keywords = $meta->getAttribute('content');
if($meta->getAttribute('property') == 'og:image')
$ogimage = $meta->getAttribute('content');
if($meta->getAttribute('rel') == 'image_src')
$relimage = $meta->getAttribute('content');
}
if( empty($ogimage) ) {
$metaimage = $relimage;
} else {
$metaimage = $ogimage;
}
Perhaps you have to make sure that your url header have content-type -> charset to utf-8 or appropriate one. You have to make sure that your url is not content none Ascii character or make sure you have properly set the appropriate "character’s encoder". Maybe i haven’t well understood your problem, however look at this example which have not relation to your code but can be useful:
$url = "http://www.example.com/services/calculation";
$page = "/services/calculation";
$headers = array(
"POST ".$page." HTTP/1.0",
"Content-type: text/xml;charset=\"utf-8\"",
"Accept: text/xml",
"Cache-Control: no-cache",
"Pragma: no-cache",
"SOAPAction: \"run\"",
"Content-length: ".strlen($xml_data),
"Authorization: Basic " . base64_encode($credentials)
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_USERAGENT, $defined_vars['HTTP_USER_AGENT']);
Solution:
add this below
Find:
$html = file_get_contents_curl($url);
Add beow it:
//Change encoding to UTF-8 from ISO-8859-1
$html = iconv('UTF-8', 'ISO-8859-1//TRANSLIT', $html);
I'm using this link in order to add new subsciption entry:
https://graph.facebook.com/XXX/subscriptions?access_token=YYY&object=payments&callback_url=http://xxx/rlcallback.php&fields=actions,disputes&verify_token=ZZZ
For some reason, I get error:
{
"error": {
"message": "(#100) Invalid object. object should be url or open graph object id.",
"type": "OAuthException",
"code": 100
}
}
But the object "payments" inside my link is clearly valid. What am I missing here?
Make sure you are using the correct parameters: object, callback_url, fields, verify_token...and of course the access_token.
Also (and that may be the problem in this case), you have to use POST, not GET. You can either use CURL with POST to subscribe to the Realtime API, or you just use one of the SDKs as explained in the Facebook docs: https://developers.facebook.com/docs/graph-api/reference/v2.1/app/subscriptions
Here is one example with CURL:
$appsecretProof = hash_hmac('sha256', FBAPPID . '|' . FBSECRET, FBSECRET);
$ch = curl_init();
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'facebook-php');
$postData = 'object=page' .
'&callback_url=' . urlencode('http://yourdomain.com/callback.php') .
'&fields=feed' .
'&verify_token=somethingfancy' .
'&access_token=' . FBAPPID . '|' . FBSECRET .
'&appsecret_proof=' . $appsecretProof;
curl_setopt($ch, CURLOPT_URL, 'https://graph.facebook.com/' . FBAPPID . '/subscriptions');
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
$curlResult = curl_exec($ch);
you need to specify object, callback_url, fields and verify_token parameters as your curl post parameters
example:
curl -F 'object=user' \
-F 'callback_url=' \
-F 'fields=checkins' \
-F 'verify_token=' \
"https://graph.facebook.com//subscriptions?access_token=
How to get shipping address with TOKEN using paypal REST api? I found this useful but I cant see example of usage anywhere.
I struggled with this issue a lot and finally found solution, so I want to share it if anyone else need it.
So question: How to get order details with TOKEN?
Add this function :
function PPHttpPost($methodName_, $nvpStr_) {
$environment = 'sandbox'; // or 'beta-sandbox' or 'live'
// Set up your API credentials, PayPal end point, and API version.
$API_UserName = urlencode('xxxxxxxxxx');
$API_Password = urlencode('xxxxxxxxxx');
$API_Signature = urlencode('xxxxxxxxxx');
$API_Endpoint = "https://api-3t.paypal.com/nvp";
if("sandbox" === $environment || "beta-sandbox" === $environment) {
$API_Endpoint = "https://api-3t.$environment.paypal.com/nvp";
}
$version = urlencode('85.0');
// Set the curl parameters.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $API_Endpoint);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
// Turn off the server and peer verification (TrustManager Concept).
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
// Set the API operation, version, and API signature in the request.
$nvpreq = "METHOD=$methodName_&VERSION=$version&PWD=$API_Password&USER=$API_UserName&SIGNATURE=$API_Signature$nvpStr_";
// Set the request as a POST FIELD for curl.
curl_setopt($ch, CURLOPT_POSTFIELDS, $nvpreq);
// Get response from the server.
$httpResponse = curl_exec($ch);
if(!$httpResponse) {
exit('$methodName_ failed: '.curl_error($ch).'('.curl_errno($ch).')');
}
// Extract the response details.
$httpResponseAr = explode("&", $httpResponse);
$httpParsedResponseAr = array();
foreach ($httpResponseAr as $i => $value) {
$tmpAr = explode("=", $value);
if(sizeof($tmpAr) > 1) {
$httpParsedResponseAr[$tmpAr[0]] = $tmpAr[1];
}
}
if((0 == sizeof($httpParsedResponseAr)) || !array_key_exists('ACK', $httpParsedResponseAr)) {
exit("Invalid HTTP Response for POST request($nvpreq) to $API_Endpoint.");
}
return $httpParsedResponseAr;
}
and simply make a call to that function :
// Set request-specific fields.
$token = urlencode(htmlspecialchars($data['TOKEN'])); //$data['TOKEN'] is token
// Add request-specific fields to the request string.
$nvpStr = "&TOKEN=$token";
$httpParsedResponseAr = $this->PPHttpPost('GetExpressCheckoutDetails', $nvpStr);
print_r($httpParsedResponseAr); // will hold all details such as shipping address, country...
additionally you can add check if payment was successful:
if( "SUCCESS" == strtoupper($httpParsedResponseAr["ACK"]) || "SUCCESSWITHWARNING" == strtoupper($httpParsedResponseAr["ACK"]) ) { .. }
reference
I'm trying to use this site https://www.oneall.com/ to add social login to a test site. After setting up the code and the login I still don't know how to extract user data from access token. Here's the link I get:
http://MYACCOUNT.api.oneall.com/socialize/redirect.html?provider_connection_token=ACCESS TOKEN HERE
I get this code by the call back page like this
if ( ! empty ($_POST['connection_token']))
{
echo "Connection token received: ".$_POST['connection_token'];
}
else
{
echo "No connection token received";
}
if ( ! empty ($_POST['connection_token']))
{
$token = $_POST['connection_token'];
$site_subdomain = 'myaccountname';
$site_public_key = 'public key';
$site_private_key = 'private key';
$site_domain = $site_subdomain.'.api.oneall.com';
$resource_uri = 'https://'.$site_domain.'/connections/'.$token .'.json';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $resource_uri);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_USERPWD, $site_public_key . ":" . $site_private_key);
curl_setopt($curl, CURLOPT_TIMEOUT, 15);
curl_setopt($curl, CURLOPT_VERBOSE, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($curl, CURLOPT_FAILONERROR, 0);
$result_json = curl_exec($curl);
if ($result_json === false)
{
echo 'Curl error: ' . curl_error($curl). '<br />';
echo 'Curl info: ' . curl_getinfo($curl). '<br />';
curl_close($curl);
}
else
{
curl_close($curl);
$json = json_decode ($result_json);
$data = $json->response->result->data;
if ($data->plugin->key == 'social_login')
{
if ($data->plugin->data->status == 'success')
{
$user_token = $data->user->user_token;
$user_id = GetUserIdForUserToken($user_token);
if ($user_id === null)
{
LinkUserTokenToUserId ($user_token, $user_id);
}
else
{
}
}
}
}
}
I need to learn how to extract data now and a little example about extracting the user name by this code.
You can use the access token to get the connection details from oneall using their api
You use the connection_token to get the connection details (including
the user's Facebook profile data).
example
http://MYACCOUNT.api.oneall.com/connections/ACCESS TOKEN HERE.json -->>for json formatted data
oneall docs
Once you get the user's token, you then need to make a API call to Facebook, e.g. https://graph.facebook.com/me/?access_token={$access_token}
If the $access_token is correct, Facebook should return the user's details, including name, username and any other details you've asked for.