always: https://www.google.com/accounts/o8/ud
i got wordpress openid ok. so i think is is just discovery phase got some probelms..
<?php $ch = curl_init();
$url = 'https://www.google.com/accounts/o8/id';
$url = $url.'?';
$url = $url.'openid.mode=checkid_setup';
$url = $url.'&openid.ns=http://specs.openid.net/auth/2.0';
$url = $url.'&openid.claimed_id=http://specs.openid.net/auth/2.0/identifier_select';
$url = $url.'&openid.identity=http://specs.openid.net/auth/2.0/identifier_select';
$url = $url.'&openid.return_to='.site_url().'/user/openid/login_callback';
$url = $url.'&openid.realm=http://www.example.com/';
// set url
curl_setopt($ch, CURLOPT_URL, $url);
//return the transfer as a string
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER,array("Accept: */*"));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
// $output contains the output string
$xdr = curl_exec($ch);
if (!$xdr) {
die(curl_error($ch));
}
// close curl resource to free up system resources
curl_close($ch);
$xml = new SimpleXMLElement($xdr);
$url = $xml->XRD->Service->URI;
$request = $connection->begin($url);
$request always null...
Take a look at https://blog.stackoverflow.com/2009/11/google-offers-named-openids/ where Jeff explains this behavior and what the user can do about it:
Well, the good news is, now you can! Google just gave us a fantastic Thanksgiving Day present in the form of Google Profiles supporting OpenID. And with a Google Profile, you get to pick a named URL of your choice!
Your question has the right endpoint URL (the one ending in /ud), but your example code is sending the request to the identifier URL (/id), not the endpoint URL.
My above code do return https://www.google.com/accounts/o8/ud in $url, which is correct actually
the problem is, you do not need to use openid php lib, just redirect the user to https://www.google.com/accounts/o8/ud with query string like:
https://www.google.com/accounts/o8/ud?openid.mode=checkid_setup&......
Related
I am working with dr chrono API and am trying to initialized the First step which is authorisation
The API documentation is here.
Here is an Authorisation sample:
https://drchrono.com/o/authorize/?redirect_uri=REDIRECT_URI_ENCODED&response_type=code&client_id=CLIENT_ID_ENCODED&scope=SCOPES_ENCODED
Here is what I have tried:
1.) I have tried the first code below
<?php
echo "<a href='https://drchrono.com/o/authorize/?redirect_uri=https://example_site.com/return_page.php&response_type=code&client_id=myclient-id-goeshere&scope=BASE_SCOPE:[read|write]'>Authorize</a>";
?>
but when the page redirects it displays error of Invalid_scope. Below is the error link returned.
https://example_site.com/return_page.php?error=invalid_scope
2.) Using Curl
$ci = 'my-client-id-goes-here';
$ci_encode = urlencode($ci);
$uri = 'https://example_site.com/return_page.php';
$uri_encode = $uri;
$url = "https://drchrono.com/o/authorize/";
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query([
'response_type'=>'code',
'client_id'=>$ci_encode,
'redirect_uri'=>$uri_encode,
'scope'=>'BASE_SCOPE:[read|write]',
]));
$response = curl_exec($ch);
curl_close($ch);
print_r($response);
Using curl code above does even redirect me at all.
I think the major problem is the scope not properly set. How can I solve this issue?
Update
Code section for curl:
$ci = 'my-client-id';
$ci_encode = urlencode($ci);
$uri = 'https://example_site.com/return_page.php';
$uri_encode = $uri;
$url = "https://drchrono.com/o/authorize/?";
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query([
'response_type'=>'code',
'client_id'=>$ci,
'redirect_uri'=>$uri,
'scope'=>'patients:summary:read patients:summary:write calendar:read calendar:write clinical:read clinical:write'
]));
$response = curl_exec($ch);
curl_close($ch);
print_r($response);
Instead of BASE_SCOPE:[read|write] I would use patients:summary:read patients:summary:write calendar:read calendar:write clinical:read clinical:write
The docs say that you can choose among user, calendar, patients, patients:summary, billing, clinical and labs and compose a scope out of these values.
Hi i need to send sms by using php. I am using curl method to post variables in url but i cant get sms. I can get result by using get method, is there any problem in my code?
$url = 'http://online.chennaisms.com/api/mt/SendSMS?';
$postData = array();
$postData['user'] = 'abc';
$postData['password'] = 'qwftgry ';
$postData['senderid'] ='reyty';
$postData['channel'] ='Trans';
$postData['DCS'] =0;
$postData['flashsms'] =0;
$postData['number'] = 91XXXXXXXXXX;
$postData['text'] ='hai ';
$postData['route'] =28;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
$result = curl_exec($ch);
curl_close($ch);
Try to delete ? character at the end of url
I don't see any problem in your code, apart from the lack of any error-checking on the cURL transaction (by means of curl_error() etc), so you should probably look elsewhere - was an error message returned by the SMS provider, for example?
When I try to add an image to a product I don't get any errors, but the image doesn't get added.
This is my code:
function addImage($idProduct)
{
$key = 'XXXXXXXXXXXXXXXXXXX';
$url = "http://192.168.1.81/api/images/products/".$idProduct;
$image_path = 'image2.jpg';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_USERPWD, $key);
curl_setopt($ch, CURLOPT_POSTFIELDS, array('image' => '#'.$image_path.';type=image/jpg'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
echo '<h2>Image Added</h2>';
}
I also made a change on PSWebServiceLibrary.php, because Prestashop Web Service API keeps asking for authentication. This is the link where I got the code Prestashop Web Service API keeps asking for authentication .
This is the code I added:
$url .= '&ws_key=' . $this->key;
The problem is that the code to add an image was working before I made that change on PSWebServiceLibrary.php, and I don't know how to solve it.
I am using prestashop 1.6.1.5
Any help will be appreciated.
Greetings!
I think it's only a missing of "?" in your url.
If I follow your $url logic the result will be for product of ID 1234567 by example :
http://192.168.1.81/api/images/products/1234567&ws_key=ZOEJFD3429JD209AZJX0DJF20
So your server waits this url to hanlde ws_key as GET parameter :
http://192.168.1.81/api/images/products/1234567?ws_key=ZOEJFD3429JD209AZJX0DJF20
You need to add this "?" at the end of you URL like this :
$url = "http://192.168.1.81/api/images/products/".$idProduct."?";
Best Regards,
TGA
For me works like this:
curl_setopt($ch, CURLOPT_POSTFIELDS, array('image' => curl_file_create($image_path)));
Im a newbie im trying to get a script to trigger another script with Curl in PHP but it dosent seem to be sending the paramaters.
Is there a seperate function to append parameters?
<?php
$time = time();
$message = "hello world";
$urlmessage = urlencode( $message );
$ch = curl_init("http://mysite.php?message=$urlmessage&time=$time");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
?>
Could anyone point me in the right direction??
The accepted answer is good for POST, but what if OP wanted specifically to GET? Some REST APIs specify the http method and often it's no good POSTing when you should be GETting.
Here is a fragment of code that does GET with some params:
$endpoint = 'http://example.com/endpoint';
$params = array('foo' => 'bar');
$url = $endpoint . '?' . http_build_query($params);
curl_setopt($ch, CURLOPT_URL, $url);
This will cause your request to be made with GET to http://example.com/endpoint?foo=bar. This is the default http method, unless you set it to something else like POST with curl_setopt($ch, CURLOPT_POST, true) - so don't do that if you specifically need to GET.
If you need to use one of the other http methods (DELETE or PUT for example) then use curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method). This also works for GET and POST.
You need curl_setopt() along with the CURLOPT_POSTFIELDS param.
That'll POST the given params to the target page.
curl_setopt($ch, CURLOPT_POSTFIELDS, 'foo=1&bar=2&baz=3');
PS: also check http_build_query() which is handy when sending many variables.
you need set CURLOPT_POST as true and CURLOPT_POSTFIELDS => parameters
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $parameters);
a suggestion,set 'CURLOPT_RETURNTRANSFER', as true to return the transfer as a string of the return value of curl_exec($ch) instead of outputting it out directly
Here is A Simple Solution for this.
$mobile_number = $_POST['mobile_number'];
$sessionid = $_POST['session_id'];
CURLOPT_URL => 'https://xxyz.jkl.com/v2.0/search?varible_that_you_want_to_pass='.$mobile_number.'&requestId=1616581154955&locale=en-US&sessionId='.$sessionid,
I want to bypass the ajax same-origin policy by having a php page on my site that basically acts like a JSON proxy. Eg i make an ajax request like this:
mysite.com/myproxy.php?url=blah.com/api.json&a=1&b=2
It then makes a request to:
blah.com/api.json?a=1&b=2
And returns the JSON (or whatever) result to the original requester.
Now i assume i'd be stupidly reinventing the wheel if i wrote this php code (plus i don't know php!) - is there some pre-existing code to do this? I'm sure i'm not the only one who's butted my head up against the same-origin policy before.
Oh yeah JSONP isn't an option for this particular api.
Thanks all
Okay, here's something -
Slap this into a php script, call it like this
script.php?url=blah
post the contents you want posted to the server.
<?php
$curlPost = http_build_query($_POST);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $_GET['url']);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
$data = curl_exec($ch);
curl_close($ch);
echo json_encode($data);
?>
Now this script is a bit too open for my liking, so to increase security I would recommend that you add a list of domains to a white list.
So add this to the top:
$whitelist = array('http://www.google.com','http://www.ajax.com');
$list = array();
foreach($whitelist as $w)
$list[] = parse_url($w,PHP_URL_HOST);
$url = $_GET['url'];
$url = pathinfo($url,PHP_URL_HOST);
if(!in_array($url, $list)) die('no access to that domain');